Skip to content

Commit

Permalink
ZCS-16428 added support for delivryReport in SaveDraft
Browse files Browse the repository at this point in the history
added support for delivery report in scheduled messages

Refatored condition to check delegator's LDAP attr

Oprimized condition
  • Loading branch information
viditZim authored and dasiyogesh committed Feb 3, 2025
1 parent 72c8e4e commit 71f313a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 4 deletions.
64 changes: 64 additions & 0 deletions store/src/java-test/com/zimbra/cs/service/mail/SaveDraftTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,68 @@ protected Element generateResponse(ZimbraSoapContext zsc, ItemIdFormatter ifmt,
Assert.assertEquals("picked up modified content", MODIFIED_CONTENT, response.getElement(MailConstants.E_MSG).getElement(MailConstants.E_MIMEPART).getAttribute(MailConstants.E_CONTENT));
}

@Test
public void deliveryReportEnabled() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("[email protected]");

// create a draft via SOAP
Element request = new Element.JSONElement(MailConstants.SAVE_DRAFT_REQUEST);
Element m = request.addNonUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.E_SUBJECT, "dinner appt");
m.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, ORIGINAL_CONTENT);
m.addAttribute(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, "1");

Element response = new SaveDraft() {
@Override
protected Element generateResponse(ZimbraSoapContext zsc, ItemIdFormatter ifmt, OperationContext octxt,
Mailbox mbox, Message msg, boolean wantImapUid, boolean wantModSeq) {

return super.generateResponse(zsc, ifmt, octxt, mbox, msg, wantImapUid, wantModSeq);
}
}.handle(request, ServiceTestUtil.getRequestContext(acct));

Assert.assertTrue(response.getElement(MailConstants.E_MSG).getAttributeBool(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, false));
}

@Test
public void deliveryReportDisabled() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("[email protected]");

// create a draft via SOAP
Element request = new Element.JSONElement(MailConstants.SAVE_DRAFT_REQUEST);
Element m = request.addNonUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.E_SUBJECT, "dinner appt");
m.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, ORIGINAL_CONTENT);
m.addAttribute(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, "0");

Element response = new SaveDraft() {
@Override
protected Element generateResponse(ZimbraSoapContext zsc, ItemIdFormatter ifmt, OperationContext octxt,
Mailbox mbox, Message msg, boolean wantImapUid, boolean wantModSeq) {

return super.generateResponse(zsc, ifmt, octxt, mbox, msg, wantImapUid, wantModSeq);
}
}.handle(request, ServiceTestUtil.getRequestContext(acct));

Assert.assertFalse(response.getElement(MailConstants.E_MSG).getAttributeBool(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, false));
}

@Test
public void deliveryReportNotSet() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("[email protected]");

// create a draft via SOAP
Element request = new Element.JSONElement(MailConstants.SAVE_DRAFT_REQUEST);
Element m = request.addNonUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.E_SUBJECT, "dinner appt");
m.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, ORIGINAL_CONTENT);

Element response = new SaveDraft() {
@Override
protected Element generateResponse(ZimbraSoapContext zsc, ItemIdFormatter ifmt, OperationContext octxt,
Mailbox mbox, Message msg, boolean wantImapUid, boolean wantModSeq) {

return super.generateResponse(zsc, ifmt, octxt, mbox, msg, wantImapUid, wantModSeq);
}
}.handle(request, ServiceTestUtil.getRequestContext(acct));

Assert.assertFalse(response.getElement(MailConstants.E_MSG).getAttributeBool(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, false));
}
}
8 changes: 7 additions & 1 deletion store/src/java/com/zimbra/cs/mailbox/AutoSendDraftTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.zimbra.cs.mailbox;

import com.zimbra.common.service.ServiceException;
import com.zimbra.common.soap.MailConstants;
import com.zimbra.common.util.StringUtil;
import com.zimbra.common.util.ZimbraLog;
import com.zimbra.common.soap.SoapHttpTransport;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class AutoSendDraftTask extends ScheduledTask<Object> {
private Element request;
public static final String ZIMBRA_MAILBOX_APP = "ZIMBRA_MAILBOX_APP";
public static final String ZIMBRA_CONSTANT_VERSION = "1.0";
public static final String DELIVERY_RECEIPT_ENABLED = "1";


public Server getServerName() {
Expand Down Expand Up @@ -118,12 +120,16 @@ public void setRequest(Element request) {
mailSender.setIdentity(StringUtil.isNullOrEmpty(msg.getDraftIdentityId()) ? null : mbox.getAccount().getIdentityById(msg.getDraftIdentityId()));
Provisioning provisioning = Provisioning.getInstance();
Account delegatorAccount = provisioning.getAccountById(getDelegatorAccountId());
boolean deliveryReport = false;
if (null != delegatorAccount) {
if (delegatorAccount.getBooleanAttr(Provisioning.A_zimbraFeatureDeliveryStatusNotificationEnabled, false)) {
deliveryReport = DELIVERY_RECEIPT_ENABLED.equals(msg.getMimeMessage().getHeader(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, null));
}
if (Provisioning.onLocalServer(delegatorAccount)) {
delegatorMbox = MailboxManager.getInstance().getMailboxByAccount(delegatorAccount);
/* if delegator is on same server, just fetch the delegatorMbox object
and use it for sending the Mime. */
mailSender.sendMimeMessage(new OperationContext(mbox), delegatorMbox, msg.getMimeMessage());
mailSender.sendMimeMessage(new OperationContext(mbox), delegatorMbox, msg.getMimeMessage(), deliveryReport);
} else {
/* if delegator is on different server, invoke the saveDraft request on that server. */
Element reqForDelegatorAccount = getRequest();
Expand Down
5 changes: 5 additions & 0 deletions store/src/java/com/zimbra/cs/mailbox/MailSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ public ItemId sendMimeMessage(OperationContext octxt, Mailbox mbox, Boolean save
return sendMimeMessage(octxt, mbox, mm);
}

public ItemId sendMimeMessage(OperationContext operationContext, Mailbox delegatorMbox, MimeMessage mimeMessage, boolean deliveryReport) throws ServiceException {
mDeliveryReport = deliveryReport;
return sendMimeMessage(operationContext, delegatorMbox, mimeMessage);
}

/**
* Sends a message.
*/
Expand Down
7 changes: 6 additions & 1 deletion store/src/java/com/zimbra/cs/service/mail/SaveDraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public Element handle(Element request, Map<String, Object> context) throws Servi
Date d = new Date();
mm.setSentDate(d);
date = d.getTime();
mm.setHeader(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, msgElem.getAttribute(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, "0"));
} catch (Exception ignored) {
}

Expand Down Expand Up @@ -210,8 +211,12 @@ public Element handle(Element request, Map<String, Object> context) throws Servi
}
if (oct != null && delegatorMbox != null) {
mm = ParseMimeMessage.parseMimeMsgSoap(zsc, oct, delegatorMbox, msgElem, null, mimeData);
boolean deliveryReport = false;
if (delegatorAccount.getBooleanAttr(Provisioning.A_zimbraFeatureDeliveryStatusNotificationEnabled, false)) {
deliveryReport = msgElem.getAttributeBool(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, false);
}
SendMsg.doSendMessage(oct, delegatorMbox, mm, mimeData.uploads, null, "r", null, null, false,
false, false, false);
false, false, deliveryReport);
}
Element response = zsc.createElement(MailConstants.SAVE_DRAFT_RESPONSE);
response.addElement(MailConstants.E_MSG);
Expand Down
4 changes: 2 additions & 2 deletions store/src/java/com/zimbra/cs/service/mail/SendMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public Element handle(Element request, Map<String, Object> context, QName respQn
boolean noSaveToSent = request.getAttributeBool(MailConstants.A_NO_SAVE_TO_SENT, false);
boolean fetchSavedMsg = request.getAttributeBool(MailConstants.A_FETCH_SAVED_MSG, false);
boolean deliveryReport = false;
if (authAcct.getBooleanAttr(Provisioning.A_zimbraFeatureDeliveryStatusNotificationEnabled, false)) {
deliveryReport = request.getAttributeBool(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, false);
if (mbox.getAccount().getBooleanAttr(Provisioning.A_zimbraFeatureDeliveryStatusNotificationEnabled, false)) {
deliveryReport = msgElem.getAttributeBool(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, false);
}

String origId = msgElem.getAttribute(MailConstants.A_ORIG_ID, null);
Expand Down
4 changes: 4 additions & 0 deletions store/src/java/com/zimbra/cs/service/mail/ToXML.java
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,10 @@ private static Element encodeMessageAsMPHelper(boolean bestEffort, Element paren
m.addAttribute(MailConstants.E_IN_REPLY_TO, StringUtil.stripControlCharacters(inReplyTo),
Element.Disposition.CONTENT);
}
String deliveryReport = mm.getHeader(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, null);
if (!StringUtil.isNullOrEmpty(deliveryReport)) {
m.addAttribute(MailConstants.A_DELIVERY_RECEIPT_NOTIFICATION, StringUtil.stripControlCharacters(deliveryReport));
}
if (msg.getDraftAutoSendTime() != 0) {
m.addAttribute(MailConstants.A_AUTO_SEND_TIME, msg.getDraftAutoSendTime());
}
Expand Down

0 comments on commit 71f313a

Please sign in to comment.