/**
   * ZimbraAccount.AccountA() sends a two-hour appointment to app.zGetActiveAccount() with subject
   * and start time
   *
   * @param subject
   * @param start
   * @throws HarnessException
   */
  private void SendCreateAppointmentRequest(String subject, ZDate start) throws HarnessException {

    ZimbraAccount.AccountA()
        .soapSend(
            "<CreateAppointmentRequest xmlns='urn:zimbraMail'>"
                + "<m>"
                + "<inv method='REQUEST' type='event' status='CONF' draft='0' class='PUB' fb='B' transp='O' allDay='0' name='"
                + subject
                + "'>"
                + "<s d='"
                + start.toTimeZone(ZTimeZone.TimeZoneEST.getID()).toYYYYMMDDTHHMMSS()
                + "' tz='"
                + ZTimeZone.TimeZoneEST.getID()
                + "'/>"
                + "<e d='"
                + start.addHours(2).toTimeZone(ZTimeZone.TimeZoneEST.getID()).toYYYYMMDDTHHMMSS()
                + "' tz='"
                + ZTimeZone.TimeZoneEST.getID()
                + "'/>"
                + "<or a='"
                + ZimbraAccount.AccountA().EmailAddress
                + "'/>"
                + "<at role='REQ' ptst='NE' rsvp='1' a='"
                + app.zGetActiveAccount().EmailAddress
                + "'/>"
                + "</inv>"
                + "<e a='"
                + app.zGetActiveAccount().EmailAddress
                + "' t='t'/>"
                + "<su>"
                + subject
                + "</su>"
                + "<mp content-type='text/plain'>"
                + "<content>content</content>"
                + "</mp>"
                + "</m>"
                + "</CreateAppointmentRequest>");
  }
  @Bugs(ids = "69132")
  @Test(
      description = "Accept a meeting using Accept button from invitation message",
      groups = {"smoke"})
  public void AcceptMeeting_01() throws HarnessException {

    // ------------------------ Test data ------------------------------------

    String apptSubject = "appointment" + ZimbraSeleniumProperties.getUniqueString();

    Calendar now = Calendar.getInstance();
    ZDate startUTC =
        new ZDate(
            now.get(Calendar.YEAR),
            now.get(Calendar.MONTH) + 1,
            now.get(Calendar.DAY_OF_MONTH),
            12,
            0,
            0);
    ZDate endUTC =
        new ZDate(
            now.get(Calendar.YEAR),
            now.get(Calendar.MONTH) + 1,
            now.get(Calendar.DAY_OF_MONTH),
            14,
            0,
            0);

    // --------------- Creating invitation (organizer) ----------------------------

    ZimbraAccount.AccountA()
        .soapSend(
            "<CreateAppointmentRequest xmlns='urn:zimbraMail'>"
                + "<m>"
                + "<inv method='REQUEST' type='event' status='CONF' draft='0' class='PUB' fb='B' transp='O' allDay='0' name='"
                + apptSubject
                + "'>"
                + "<s d='"
                + startUTC.toTimeZone(ZTimeZone.TimeZoneEST.getID()).toYYYYMMDDTHHMMSS()
                + "' tz='"
                + ZTimeZone.TimeZoneEST.getID()
                + "'/>"
                + "<e d='"
                + endUTC.toTimeZone(ZTimeZone.TimeZoneEST.getID()).toYYYYMMDDTHHMMSS()
                + "' tz='"
                + ZTimeZone.TimeZoneEST.getID()
                + "'/>"
                + "<or a='"
                + ZimbraAccount.AccountA().EmailAddress
                + "'/>"
                + "<at role='REQ' ptst='NE' rsvp='1' a='"
                + app.zGetActiveAccount().EmailAddress
                + "'/>"
                + "</inv>"
                + "<e a='"
                + app.zGetActiveAccount().EmailAddress
                + "' t='t'/>"
                + "<su>"
                + apptSubject
                + "</su>"
                + "<mp content-type='text/plain'>"
                + "<content>content</content>"
                + "</mp>"
                + "</m>"
                + "</CreateAppointmentRequest>");

    // --------------- Login to attendee & accept invitation
    // ----------------------------------------------------

    // Refresh the view
    app.zPageMail.zToolbarPressButton(Button.B_GETMAIL);

    // Select the invitation
    DisplayMail display = (DisplayMail) app.zPageMail.zListItem(Action.A_LEFTCLICK, apptSubject);

    // Click Accept
    display.zPressButton(Button.B_ACCEPT);

    // ---------------- Verification at organizer & invitee side both
    // -------------------------------------

    // --- Check that the organizer shows the attendee as "ACCEPT" ---

    // Organizer: Search for the appointment (InvId)
    ZimbraAccount.AccountA()
        .soapSend(
            "<SearchRequest xmlns='urn:zimbraMail' types='appointment' calExpandInstStart='"
                + startUTC.addDays(-10).toMillis()
                + "' calExpandInstEnd='"
                + endUTC.addDays(10).toMillis()
                + "'>"
                + "<query>"
                + apptSubject
                + "</query>"
                + "</SearchRequest>");

    String organizerInvId = ZimbraAccount.AccountA().soapSelectValue("//mail:appt", "invId");

    // Get the appointment details
    ZimbraAccount.AccountA()
        .soapSend("<GetAppointmentRequest  xmlns='urn:zimbraMail' id='" + organizerInvId + "'/>");

    String attendeeStatus =
        ZimbraAccount.AccountA()
            .soapSelectValue(
                "//mail:at[@a='" + app.zGetActiveAccount().EmailAddress + "']", "ptst");

    // Verify attendee status shows as psts=AC
    ZAssert.assertEquals(attendeeStatus, "AC", "Verify that the attendee shows as 'ACCEPTED'");

    // --- Check that the attendee showing status as "ACCEPT" ---

    // Attendee: Search for the appointment (InvId)
    app.zGetActiveAccount()
        .soapSend(
            "<SearchRequest xmlns='urn:zimbraMail' types='appointment' calExpandInstStart='"
                + startUTC.addDays(-10).toMillis()
                + "' calExpandInstEnd='"
                + endUTC.addDays(10).toMillis()
                + "'>"
                + "<query>"
                + apptSubject
                + "</query>"
                + "</SearchRequest>");

    String attendeeInvId = app.zGetActiveAccount().soapSelectValue("//mail:appt", "invId");

    // Get the appointment details
    app.zGetActiveAccount()
        .soapSend("<GetAppointmentRequest  xmlns='urn:zimbraMail' id='" + attendeeInvId + "'/>");

    String myStatus =
        app.zGetActiveAccount()
            .soapSelectValue(
                "//mail:at[@a='" + app.zGetActiveAccount().EmailAddress + "']", "ptst");

    // Verify attendee status shows as psts=AC
    ZAssert.assertEquals(myStatus, "AC", "Verify that the attendee shows as 'ACCEPTED'");
  }
  @Bugs(ids = "69132")
  @Test(
      description = "Accept meeting using 'Accept -> Edit Reply' and verify modified content",
      groups = {"functional"})
  public void AcceptMeeting_04() throws HarnessException {

    // ------------------------ Test data ------------------------------------

    String apptSubject = "appointment" + ZimbraSeleniumProperties.getUniqueString();
    String modifiedBody = "modified" + ZimbraSeleniumProperties.getUniqueString();

    Calendar now = Calendar.getInstance();
    ZDate startUTC =
        new ZDate(
            now.get(Calendar.YEAR),
            now.get(Calendar.MONTH) + 1,
            now.get(Calendar.DAY_OF_MONTH),
            12,
            0,
            0);
    ZDate endUTC =
        new ZDate(
            now.get(Calendar.YEAR),
            now.get(Calendar.MONTH) + 1,
            now.get(Calendar.DAY_OF_MONTH),
            14,
            0,
            0);

    // --------------- Creating invitation (organizer) ----------------------------

    ZimbraAccount.AccountA()
        .soapSend(
            "<CreateAppointmentRequest xmlns='urn:zimbraMail'>"
                + "<m>"
                + "<inv method='REQUEST' type='event' status='CONF' draft='0' class='PUB' fb='B' transp='O' allDay='0' name='"
                + apptSubject
                + "'>"
                + "<s d='"
                + startUTC.toTimeZone(ZTimeZone.TimeZoneEST.getID()).toYYYYMMDDTHHMMSS()
                + "' tz='"
                + ZTimeZone.TimeZoneEST.getID()
                + "'/>"
                + "<e d='"
                + endUTC.toTimeZone(ZTimeZone.TimeZoneEST.getID()).toYYYYMMDDTHHMMSS()
                + "' tz='"
                + ZTimeZone.TimeZoneEST.getID()
                + "'/>"
                + "<or a='"
                + ZimbraAccount.AccountA().EmailAddress
                + "'/>"
                + "<at role='REQ' ptst='NE' rsvp='1' a='"
                + app.zGetActiveAccount().EmailAddress
                + "'/>"
                + "</inv>"
                + "<e a='"
                + app.zGetActiveAccount().EmailAddress
                + "' t='t'/>"
                + "<su>"
                + apptSubject
                + "</su>"
                + "<mp content-type='text/plain'>"
                + "<content>content</content>"
                + "</mp>"
                + "</m>"
                + "</CreateAppointmentRequest>");

    // --------------- Login to attendee & accept invitation
    // ----------------------------------------------------

    // Refresh the view
    app.zPageMail.zToolbarPressButton(Button.B_GETMAIL);

    // Select the invitation
    DisplayMail display = (DisplayMail) app.zPageMail.zListItem(Action.A_LEFTCLICK, apptSubject);

    // Click Accept -> Edit Reply , which will open a new reply compose
    FormMailNew editReply =
        (FormMailNew) display.zPressButtonPulldown(Button.B_ACCEPT, Button.O_ACCEPT_EDIT_REPLY);
    editReply.zFillField(Field.Body, modifiedBody);
    editReply.zSubmit();

    // ---------------- Verification at organizer & invitee side both
    // -------------------------------------

    // --- Check that the organizer shows the attendee as "ACCEPT" ---

    // Organizer: Search for the appointment (InvId)
    ZimbraAccount.AccountA()
        .soapSend(
            "<SearchRequest xmlns='urn:zimbraMail' types='appointment' calExpandInstStart='"
                + startUTC.addDays(-10).toMillis()
                + "' calExpandInstEnd='"
                + endUTC.addDays(10).toMillis()
                + "'>"
                + "<query>"
                + apptSubject
                + "</query>"
                + "</SearchRequest>");

    String organizerInvId = ZimbraAccount.AccountA().soapSelectValue("//mail:appt", "invId");

    // Get the appointment details
    ZimbraAccount.AccountA()
        .soapSend("<GetAppointmentRequest  xmlns='urn:zimbraMail' id='" + organizerInvId + "'/>");

    String attendeeStatus =
        ZimbraAccount.AccountA()
            .soapSelectValue(
                "//mail:at[@a='" + app.zGetActiveAccount().EmailAddress + "']", "ptst");

    // Verify attendee status shows as psts=AC
    ZAssert.assertEquals(attendeeStatus, "AC", "Verify that the attendee shows as 'ACCEPTED'");

    // --- Check that the attendee showing status as "ACCEPT" ---

    // Attendee: Search for the appointment (InvId)
    app.zGetActiveAccount()
        .soapSend(
            "<SearchRequest xmlns='urn:zimbraMail' types='appointment' calExpandInstStart='"
                + startUTC.addDays(-10).toMillis()
                + "' calExpandInstEnd='"
                + endUTC.addDays(10).toMillis()
                + "'>"
                + "<query>"
                + apptSubject
                + "</query>"
                + "</SearchRequest>");

    String attendeeInvId = app.zGetActiveAccount().soapSelectValue("//mail:appt", "invId");

    // Get the appointment details
    app.zGetActiveAccount()
        .soapSend("<GetAppointmentRequest  xmlns='urn:zimbraMail' id='" + attendeeInvId + "'/>");

    String myStatus =
        app.zGetActiveAccount()
            .soapSelectValue(
                "//mail:at[@a='" + app.zGetActiveAccount().EmailAddress + "']", "ptst");

    // Verify attendee status shows as psts=AC
    ZAssert.assertEquals(myStatus, "AC", "Verify that the attendee shows as 'ACCEPTED'");

    // Organizer: Search for the appointment response
    String inboxId =
        FolderItem.importFromSOAP(ZimbraAccount.AccountA(), FolderItem.SystemFolder.Inbox).getId();

    ZimbraAccount.AccountA()
        .soapSend(
            "<SearchRequest xmlns='urn:zimbraMail' types='message'>"
                + "<query>inid:"
                + inboxId
                + " subject:("
                + apptSubject
                + ")</query>"
                + "</SearchRequest>");

    // Verify message body content
    String body = ZimbraAccount.AccountA().soapSelectValue("//mail:m/mail:fr", null);
    ZAssert.assertStringContains(body, modifiedBody, "Verify modified body value");
  }