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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations