Search in sources :

Example 6 with ParsedAddress

use of com.zimbra.cs.mime.ParsedAddress 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)

Example 7 with ParsedAddress

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

the class Mailbox method createAutoContact.

/**
 * Creates new contacts in AUTO_CONTACTS folder.
 * Note: Its upto the caller to check whether the email addresses in the list pre-exist.
 *
 * @param octxt operation context
 * @param addrs email addresses
 * @return newly created contacts
 */
public List<Contact> createAutoContact(OperationContext octxt, Collection<InternetAddress> addrs) throws IOException {
    if (addrs.isEmpty()) {
        return Collections.emptyList();
    }
    List<Contact> result = new ArrayList<Contact>(addrs.size());
    String locale = octxt != null && octxt.getAuthenticatedUser() != null ? octxt.getAuthenticatedUser().getPrefLocale() : null;
    boolean nameFormatLastFirst = false;
    if (locale != null && locale.equals("ja")) {
        nameFormatLastFirst = true;
    }
    for (InternetAddress addr : addrs) {
        ZimbraLog.mailbox.debug("Auto-adding new contact addr=%s", addr);
        try {
            result.add(createContact(octxt, new ParsedContact(new ParsedAddress(addr, nameFormatLastFirst).getAttributes()), Mailbox.ID_FOLDER_AUTO_CONTACTS, null));
        } catch (ServiceException e) {
            if (e.getCode().equals(MailServiceException.TOO_MANY_CONTACTS)) {
                ZimbraLog.mailbox.warn("Aborting contact addition, " + "Failed to auto-add contact addr=%s", addr, e);
                return result;
            }
            ZimbraLog.mailbox.warn("Failed to auto-add contact addr=%s", addr, e);
        }
    }
    return result;
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) ParsedContact(com.zimbra.cs.mime.ParsedContact) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ModifyContact(com.zimbra.cs.redolog.op.ModifyContact) ParsedContact(com.zimbra.cs.mime.ParsedContact) CreateContact(com.zimbra.cs.redolog.op.CreateContact) ParsedAddress(com.zimbra.cs.mime.ParsedAddress)

Example 8 with ParsedAddress

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

the class Message method getSortRecipients.

@Override
public String getSortRecipients() {
    List<InternetAddress> iaddrs = com.zimbra.common.mime.InternetAddress.parseHeader(getRecipients());
    if (iaddrs == null || iaddrs.isEmpty()) {
        return null;
    }
    List<ParsedAddress> paddrs = new ArrayList<ParsedAddress>(iaddrs.size());
    for (InternetAddress iaddr : iaddrs) {
        paddrs.add(new ParsedAddress(iaddr));
    }
    return DbMailItem.normalize(ParsedAddress.getSortString(paddrs), DbMailItem.MAX_RECIPIENTS_LENGTH);
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) ArrayList(java.util.ArrayList) ParsedAddress(com.zimbra.cs.mime.ParsedAddress)

Example 9 with ParsedAddress

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

the class FacebookTest method executeBasic.

@Override
protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException {
    if (mail instanceof DummyMailAdapter) {
        return true;
    }
    if (!(mail instanceof ZimbraMailAdapter)) {
        return false;
    }
    ZimbraMailAdapter adapter = (ZimbraMailAdapter) mail;
    ParsedAddress sender = adapter.getParsedMessage().getParsedSender();
    if (!Strings.isNullOrEmpty(sender.emailPart)) {
        String email = sender.emailPart.toLowerCase();
        if (email.endsWith("@facebookmail.com") && email.startsWith("notification+")) {
            return true;
        }
    }
    return false;
}
Also used : DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter) ParsedAddress(com.zimbra.cs.mime.ParsedAddress)

Example 10 with ParsedAddress

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

the class LinkedInTest method executeBasic.

@Override
protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException {
    if (mail instanceof DummyMailAdapter) {
        return true;
    }
    if (!(mail instanceof ZimbraMailAdapter)) {
        return false;
    }
    ZimbraMailAdapter adapter = (ZimbraMailAdapter) mail;
    ParsedAddress sender = adapter.getParsedMessage().getParsedSender();
    if (!Strings.isNullOrEmpty(sender.emailPart) && ADDRESSES.contains(sender.emailPart.toLowerCase())) {
        return true;
    }
    return false;
}
Also used : DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter) ParsedAddress(com.zimbra.cs.mime.ParsedAddress)

Aggregations

ParsedAddress (com.zimbra.cs.mime.ParsedAddress)10 DummyMailAdapter (com.zimbra.cs.filter.DummyMailAdapter)4 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)4 InternetAddress (com.zimbra.common.mime.InternetAddress)2 ServiceException (com.zimbra.common.service.ServiceException)2 ArrayList (java.util.ArrayList)2 Element (com.zimbra.common.soap.Element)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)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 ParsedContact (com.zimbra.cs.mime.ParsedContact)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 CreateContact (com.zimbra.cs.redolog.op.CreateContact)1 ModifyContact (com.zimbra.cs.redolog.op.ModifyContact)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 MessagingException (javax.mail.MessagingException)1 MimeMessage (javax.mail.internet.MimeMessage)1