Search in sources :

Example 1 with TagSpecifier

use of com.zimbra.client.ZMailbox.TagSpecifier in project zm-mailbox by Zimbra.

the class AppendMessage method store.

private int store(ImapMailboxStore mboxStore, FolderStore folderStore) throws ImapSessionClosedException, ServiceException, IOException {
    if (mboxStore instanceof LocalImapMailboxStore) {
        boolean idxAttach = ((LocalImapMailboxStore) mboxStore).attachmentsIndexingEnabled();
        Long receivedDate = date != null ? date.getTime() : null;
        ParsedMessage pm = new ParsedMessage(content, receivedDate, idxAttach);
        try {
            if (!pm.getSender().isEmpty()) {
                InternetAddress ia = new JavaMailInternetAddress(pm.getSender());
                if (mboxStore.addressMatchesAccountOrSendAs(ia.getAddress())) {
                    flags |= Flag.BITMASK_FROM_ME;
                }
            }
        } catch (Exception e) {
        }
        int folderId = Integer.parseInt(folderStore.getFolderIdAsString());
        DeliveryOptions dopt = new DeliveryOptions().setFolderId(folderId).setNoICal(true).setFlags(flags).setTags(tags);
        Message msg = ((LocalImapMailboxStore) mboxStore).getMailbox().addMessage(handler.getContext(), pm, dopt, null);
        if (msg != null && sflags != 0 && handler.getState() == ImapHandler.State.SELECTED) {
            ImapFolder selectedFolder = handler.getSelectedFolder();
            // (note that this leaves session flags unset on remote appended messages)
            if (selectedFolder != null) {
                ImapMessage i4msg = selectedFolder.getById(msg.getId());
                if (i4msg != null) {
                    i4msg.setSessionFlags(sflags, selectedFolder);
                }
            }
        }
        return msg == null ? -1 : msg.getId();
    }
    if (mboxStore instanceof RemoteImapMailboxStore) {
        String id;
        try (InputStream is = content.getInputStream()) {
            TagSpecifier tagSpec = tags.isEmpty() ? null : TagSpecifier.tagByName(Joiner.on(",").join(tags));
            long receivedDate = date != null ? date.getTime() : 0;
            id = ((RemoteImapMailboxStore) mboxStore).getZMailbox().addMessage(folderStore.getFolderIdAsString(), Flag.toString(flags), tagSpec, receivedDate, is, content.getRawSize(), true);
        }
        int msgId = new ItemId(id, mboxStore.getAccountId()).getId();
        ImapFolder selectedFolder = handler.getSelectedFolder();
        if (selectedFolder != null) {
            ImapMessage i4msg = selectedFolder.getById(msgId);
            if (i4msg != null) {
                i4msg.setSessionFlags(sflags, selectedFolder);
            }
        }
        return msgId;
    }
    return -1;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) TagSpecifier(com.zimbra.client.ZMailbox.TagSpecifier) ItemId(com.zimbra.cs.service.util.ItemId) MessagingException(javax.mail.MessagingException) ServiceException(com.zimbra.common.service.ServiceException) ImapMaximumSizeExceededException(com.zimbra.cs.imap.ImapParseException.ImapMaximumSizeExceededException) ParseException(java.text.ParseException) IOException(java.io.IOException) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions)

Aggregations

TagSpecifier (com.zimbra.client.ZMailbox.TagSpecifier)1 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)1 ServiceException (com.zimbra.common.service.ServiceException)1 ImapMaximumSizeExceededException (com.zimbra.cs.imap.ImapParseException.ImapMaximumSizeExceededException)1 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)1 Message (com.zimbra.cs.mailbox.Message)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 ItemId (com.zimbra.cs.service.util.ItemId)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1 MessagingException (javax.mail.MessagingException)1 InternetAddress (javax.mail.internet.InternetAddress)1