Search in sources :

Example 1 with SenderList

use of com.zimbra.cs.mailbox.SenderList in project zm-mailbox by Zimbra.

the class ToXML method encodeConversationSummary.

private static Element encodeConversationSummary(Element parent, ItemIdFormatter ifmt, OperationContext octxt, Conversation conv, List<Message> msgs, Message msgHit, OutputParticipants output, int fields, boolean alwaysSerialize) throws ServiceException {
    boolean addFirstHitRecips = msgHit != null && (output == OutputParticipants.PUT_RECIPIENTS);
    boolean addAggregatedRecips = !addFirstHitRecips && (output == OutputParticipants.PUT_BOTH);
    boolean addSenders = (output == OutputParticipants.PUT_BOTH || output == OutputParticipants.PUT_SENDERS) && needToOutput(fields, Change.SENDERS);
    Mailbox mbox = conv.getMailbox();
    boolean noneVisible = msgs != null && msgs.isEmpty();
    Element c = noneVisible && !alwaysSerialize ? null : encodeConversationCommon(parent, ifmt, octxt, conv, msgs, fields);
    if (noneVisible || c == null) {
        return c;
    }
    if (needToOutput(fields, Change.DATE)) {
        c.addAttribute(MailConstants.A_DATE, msgHit != null ? msgHit.getDate() : conv.getDate());
    }
    if (needToOutput(fields, Change.SUBJECT)) {
        c.addAttribute(MailConstants.E_SUBJECT, msgHit != null ? msgHit.getSubject() : conv.getSubject(), Element.Disposition.CONTENT);
    }
    if (needToOutput(fields, Change.FLAGS | Change.UNREAD)) {
        c.addAttribute(MailConstants.A_UNREAD, conv.getUnreadCount());
    }
    List<Message> msgsByConv = null;
    if (fields == NOTIFY_FIELDS && msgHit != null) {
        /*
             * bug: 75104
             * we need to encode fragment of the first message in the conv instead of the first hit
             */
        if (msgHit.inTrash() || msgHit.inSpam()) {
            msgsByConv = mbox.getMessagesByConversation(octxt, conv.getId(), SortBy.DATE_DESC, 1);
        } else {
            msgsByConv = mbox.getMessagesByConversation(octxt, conv.getId(), SortBy.DATE_DESC, -1, true);
        }
        c.addAttribute(MailConstants.E_FRAG, msgsByConv.isEmpty() == false ? msgsByConv.get(0).getFragment() : msgHit.getFragment(), Element.Disposition.CONTENT);
    }
    if (addFirstHitRecips && msgHit != null) {
        addEmails(c, Mime.parseAddressHeader(msgHit.getRecipients()), EmailType.TO);
    }
    boolean elided = false;
    if (addSenders) {
        SenderList sl;
        try {
            if (msgs != null) {
                sl = new SenderList();
                for (Message msg : msgs) {
                    if (!msg.isTagged(Flag.FlagInfo.DELETED)) {
                        sl.add(msg);
                    }
                }
            } else {
                sl = mbox.getConversationSenderList(conv.getId());
            }
        } catch (SenderList.RefreshException slre) {
            ZimbraLog.soap.warn("out-of-order messages returned for conversation " + conv.getId());
            return c;
        } catch (ServiceException e) {
            return c;
        }
        elided = elided || sl.isElided();
        for (ParsedAddress pa : sl.getLastAddresses()) {
            encodeEmail(c, pa, EmailType.FROM);
        }
    }
    if (addAggregatedRecips) {
        ToRecipsList aggregatedToRecips;
        aggregatedToRecips = new ToRecipsList();
        if (msgs != null) {
            for (Message msg : msgs) {
                if (!msg.isTagged(Flag.FlagInfo.DELETED)) {
                    aggregatedToRecips.add(msg);
                }
            }
        } else {
            if (msgsByConv == null) {
                msgsByConv = mbox.getMessagesByConversation(octxt, conv.getId(), SortBy.DATE_DESC, -1, true);
            }
            if (msgsByConv != null) {
                for (Message msg : msgsByConv) {
                    if (!msg.isTagged(Flag.FlagInfo.DELETED)) {
                        aggregatedToRecips.add(msg);
                    }
                }
            }
        }
        elided = elided || aggregatedToRecips.isElided();
        for (ParsedAddress pa : aggregatedToRecips.getLastAddresses()) {
            encodeEmail(c, pa, EmailType.TO);
        }
    }
    if (elided) {
        c.addAttribute(MailConstants.A_ELIDED, true);
    }
    if (needToOutput(fields, Change.CONFLICT)) {
        c.addAttribute(MailConstants.A_CHANGE_DATE, conv.getChangeDate() / 1000);
        c.addAttribute(MailConstants.A_MODIFIED_SEQUENCE, conv.getModifiedSequence());
    }
    return c;
}
Also used : SenderList(com.zimbra.cs.mailbox.SenderList) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Element(com.zimbra.common.soap.Element) ParsedAddress(com.zimbra.cs.mime.ParsedAddress)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 Message (com.zimbra.cs.mailbox.Message)1 SenderList (com.zimbra.cs.mailbox.SenderList)1 ParsedAddress (com.zimbra.cs.mime.ParsedAddress)1 MimeMessage (javax.mail.internet.MimeMessage)1