HashSet unique = new HashSet(); addEmails(m, eecache, Mime.parseAddressHeader(mm, "From"), EmailElementCache.EMAIL_TYPE_FROM, unique); addEmails(m, eecache, Mime.parseAddressHeader(mm, "Reply-To"), EmailElementCache.EMAIL_TYPE_REPLY_TO, unique);
addEmails(m, eecache, Mime.parseAddressHeader(mm, "From"), EmailElementCache.EMAIL_TYPE_FROM); addEmails(m, eecache, Mime.parseAddressHeader(mm, "Reply-To"), EmailElementCache.EMAIL_TYPE_REPLY_TO);
	public static Element encodeMessageAsMP(Element parent, ZimbraContext lc, Message msg, boolean wantHTML, String part)	throws ServiceException {        boolean wholeMessage = (part == null || part.trim().equals(""));                Element m;        if (wholeMessage) {            m = encodeMessageCommon(parent, lc, msg, NOTIFY_FIELDS);            m.addAttribute(MailService.A_ID, lc.formatItemId(msg));        } else {            m = parent.addElement(MailService.E_MSG);            m.addAttribute(MailService.A_ID, lc.formatItemId(msg));            m.addAttribute(MailService.A_PART, part);        }        try {            MimeMessage mm = msg.getMimeMessage();            if (!wholeMessage) {                MimePart mp = Mime.getMimePart(mm, part);                if (mp == null)                    throw MailServiceException.NO_SUCH_PART(part);                Object content = Mime.getMessageContent(mp);                if (!(content instanceof MimeMessage))                    throw MailServiceException.NO_SUCH_PART(part);                mm = (MimeMessage) content;            } else                part = "";            EmailElementCache eecache = new EmailElementCache();            HashSet unique = new HashSet();            addEmails(m, eecache, Mime.parseAddressHeader(mm, "From"), EmailElementCache.EMAIL_TYPE_FROM, unique);            addEmails(m, eecache, Mime.parseAddressHeader(mm, "Reply-To"), EmailElementCache.EMAIL_TYPE_REPLY_TO, unique);            addEmails(m, eecache, Mime.parseAddressHeader(mm, "To"), EmailElementCache.EMAIL_TYPE_TO);            addEmails(m, eecache, Mime.parseAddressHeader(mm, "Cc"), EmailElementCache.EMAIL_TYPE_CC);            addEmails(m, eecache, Mime.parseAddressHeader(mm, "Bcc"), EmailElementCache.EMAIL_TYPE_BCC);            String subject = mm.getSubject();            if (subject != null)                m.addAttribute(MailService.E_SUBJECT, StringUtil.stripControlCharacters(subject), Element.DISP_CONTENT);            String messageID = mm.getMessageID();            if (messageID != null && !messageID.trim().equals(""))                m.addAttribute(MailService.E_MSG_ID_HDR, StringUtil.stripControlCharacters(messageID), Element.DISP_CONTENT);            if (wholeMessage && msg.isDraft()) {                if (msg.getDraftOrigId() > 0)                    m.addAttribute(MailService.A_ORIG_ID, lc.formatItemId(msg.getDraftOrigId()));                if (!msg.getDraftReplyType().equals(""))                    m.addAttribute(MailService.A_REPLY_TYPE, msg.getDraftReplyType());                String inReplyTo = mm.getHeader("In-Reply-To", null);                if (inReplyTo != null && !inReplyTo.equals(""))                    m.addAttribute(MailService.E_IN_REPLY_TO, StringUtil.stripControlCharacters(inReplyTo), Element.DISP_CONTENT);            }            if (!wholeMessage)                m.addAttribute(MailService.A_SIZE, mm.getSize());            java.util.Date sent = mm.getSentDate();            if (sent != null)                m.addAttribute(MailService.A_SENT_DATE, sent.getTime());                        if (msg.isInvite())                encodeInvitesForMessage(m, lc, msg, NOTIFY_FIELDS);                        List parts = Mime.getParts(mm);            if (parts != null && !parts.isEmpty()) {                MPartInfo body = Mime.getBody(parts, wantHTML);                addParts(m, (MPartInfo) parts.get(0), body, part);            }        } catch (IOException ex) {            throw ServiceException.FAILURE(ex.getMessage(), ex);        } catch (MessagingException ex) {            throw ServiceException.FAILURE(ex.getMessage(), ex);        }        return m;	}