Search in sources :

Example 91 with Message

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

the class ExistingMessageHandler method explicitKeep.

@Override
public Message explicitKeep(Collection<ActionFlag> flagActions, String[] tags) throws ServiceException {
    ZimbraLog.filter.debug("Explicitly keeping existing message %d.", messageId);
    Message msg = getMessage();
    updateTagsAndFlagsIfNecessary(msg, flagActions, tags);
    kept = true;
    return msg;
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage)

Example 92 with Message

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

the class Pop3Handler method doTOP.

private void doTOP(String arg) throws Pop3CmdException, IOException, ServiceException {
    if (state != STATE_TRANSACTION) {
        throw new Pop3CmdException("this command is only valid after a login");
    }
    int space = arg == null ? -1 : arg.indexOf(" ");
    if (space == -1) {
        throw new Pop3CmdException("please specify a message and number of lines");
    }
    String msg = arg.substring(0, space);
    int n = parseInt(arg.substring(space + 1), "unable to parse number of lines");
    if (n < 0) {
        throw new Pop3CmdException("please specify a non-negative value for number of lines");
    }
    if (msg == null || msg.equals("")) {
        throw new Pop3CmdException("please specify a message");
    }
    Message m = mailbox.getMessage(msg);
    InputStream is = null;
    try {
        is = m.getContentStream();
        sendOK("message top follows", false);
        sendMessage(is, n);
    } finally {
        ByteUtil.closeStream(is);
    }
}
Also used : Message(com.zimbra.cs.mailbox.Message) PushbackInputStream(java.io.PushbackInputStream) InputStream(java.io.InputStream)

Example 93 with Message

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

the class ImapFolderSync method appendMsgs.

private void appendMsgs(List<Integer> itemIds) throws ServiceException {
    remoteFolder.info("Appending %d message(s) to remote IMAP folder", itemIds.size());
    ImapAppender appender = newImapAppender(remoteFolder.getPath());
    for (int id : itemIds) {
        if (skipItem(id)) {
            LOG.warn("Skipping append of item %d due to previous errors", id);
            continue;
        }
        Message msg = localFolder.getMessage(id);
        if (msg == null) {
            clearError(id);
            // Message must have been deleted
            continue;
        }
        remoteFolder.debug("Appending new message with item id %d", id);
        // Bug 27924: delete tracker from source folder if it exists
        ImapMessage msgTracker = getMsgTracker(id);
        if (msgTracker != null) {
            msgTracker.delete();
        }
        try {
            long uid = appender.appendMessage(msg);
            try {
                msgTracker = tracker.getMessage(uid);
                if (msgTracker.getItemId() != id) {
                    // Another track associated with same remote message
                    // because of deduping. Delete deplicate local message
                    localFolder.deleteMessage(id);
                }
            } catch (MailServiceException.NoSuchItemException e) {
                storeImapMessage(uid, id, msg.getFlagBitmask(), true);
            }
        } catch (Exception e) {
            syncMessageFailed(id, "Append message failed", e);
        }
    }
}
Also used : PurgedMessage(com.zimbra.cs.db.DbDataSource.PurgedMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) MailException(com.zimbra.cs.mailclient.MailException) ServiceException(com.zimbra.common.service.ServiceException) SQLException(java.sql.SQLException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) RemoteServiceException(com.zimbra.common.service.RemoteServiceException)

Example 94 with Message

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

the class MailItemImport method addMessage.

public Message addMessage(OperationContext octxt, ParsedMessage pm, int size, int folderId, int flags, DeliveryContext dc) throws ServiceException, IOException {
    Message msg = null;
    CurrentUsage usage = new CurrentUsage(size);
    switch(folderId) {
        case Mailbox.ID_FOLDER_INBOX:
            try {
                List<ItemId> addedMessageIds = RuleManager.applyRulesToIncomingMessage(octxt, mbox, pm, size, dataSource.getEmailAddress(), dc, Mailbox.ID_FOLDER_INBOX, true);
                Integer newMessageId = getFirstLocalId(addedMessageIds);
                if (newMessageId == null) {
                    // Message was discarded or filed remotely
                    return null;
                } else {
                    // purgeIfNecessary(octxt, usage, pm);
                    msg = mbox.getMessageById(null, newMessageId);
                }
                // Set flags (setting of BITMASK_UNREAD is implicit)
                if (flags != Flag.BITMASK_UNREAD) {
                    // Bug 28275: Cannot set DRAFT flag after message has been created
                    flags &= ~Flag.BITMASK_DRAFT;
                    mbox.setTags(octxt, newMessageId, MailItem.Type.MESSAGE, flags, MailItem.TAG_UNCHANGED);
                }
            } catch (Exception e) {
                ZimbraLog.datasource.warn("Error applying filter rules", e);
            }
            break;
        case Mailbox.ID_FOLDER_DRAFTS:
        case Mailbox.ID_FOLDER_SENT:
            flags |= Flag.BITMASK_FROM_ME;
            break;
    }
    if (msg == null) {
        msg = mbox.addMessage(octxt, pm, new DeliveryOptions().setFolderId(folderId).setFlags(flags), null);
    }
    return msg;
}
Also used : Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ItemId(com.zimbra.cs.service.util.ItemId) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException)

Example 95 with Message

use of com.zimbra.cs.mailbox.Message 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

Message (com.zimbra.cs.mailbox.Message)442 Mailbox (com.zimbra.cs.mailbox.Mailbox)375 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)358 Test (org.junit.Test)335 Account (com.zimbra.cs.account.Account)315 OperationContext (com.zimbra.cs.mailbox.OperationContext)302 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)281 ItemId (com.zimbra.cs.service.util.ItemId)211 MimeMessage (javax.mail.internet.MimeMessage)123 SyntaxException (org.apache.jsieve.exception.SyntaxException)87 Header (javax.mail.Header)83 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)63 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)53 LmtpEnvelope (com.zimbra.cs.lmtpserver.LmtpEnvelope)46 LmtpAddress (com.zimbra.cs.lmtpserver.LmtpAddress)43 ServiceException (com.zimbra.common.service.ServiceException)41 Element (com.zimbra.common.soap.Element)41 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)36 Folder (com.zimbra.cs.mailbox.Folder)32 ZMailbox (com.zimbra.client.ZMailbox)26