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