Search in sources :

Example 6 with CalendarPartInfo

use of com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo in project zm-mailbox by Zimbra.

the class Mailbox method dedupeForSelfMsg.

public boolean dedupeForSelfMsg(ParsedMessage pm) throws ServiceException {
    if (pm == null) {
        return false;
    }
    CalendarPartInfo cpi = pm.getCalendarPartInfo();
    String msgidHeader = pm.getMessageID();
    boolean dedupe = false;
    if (msgidHeader == null) {
        return false;
    }
    // .... but only dedupe messages not carrying a calendar part
    if (mSentMessageIDs.containsKey(msgidHeader) && (cpi == null || !CalendarItem.isAcceptableInvite(getAccount(), cpi))) {
        Account acct = getAccount();
        switch(acct.getPrefDedupeMessagesSentToSelf()) {
            case dedupeAll:
                {
                    dedupe = true;
                    break;
                }
            case secondCopyifOnToOrCC:
                try {
                    dedupe = !AccountUtil.isDirectRecipient(acct, pm.getMimeMessage());
                } catch (Exception e) {
                    ZimbraLog.mailbox.info(e.getMessage());
                }
                break;
            case dedupeNone:
            default:
        }
    }
    return dedupe;
}
Also used : Account(com.zimbra.cs.account.Account) CalendarPartInfo(com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo) AccountServiceException(com.zimbra.cs.account.AccountServiceException) IOException(java.io.IOException) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) ServiceException(com.zimbra.common.service.ServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 7 with CalendarPartInfo

use of com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo in project zm-mailbox by Zimbra.

the class SetCalendarItem method getSetCalendarItemData.

static SetCalendarItemData getSetCalendarItemData(ZimbraSoapContext zsc, OperationContext octxt, Account acct, Mailbox mbox, Element e, ParseMimeMessage.InviteParser parser) throws ServiceException {
    String partStatStr = e.getAttribute(MailConstants.A_CAL_PARTSTAT, IcalXmlStrMap.PARTSTAT_NEEDS_ACTION);
    // <M>
    Element msgElem = e.getElement(MailConstants.E_MSG);
    // check to see whether the entire message has been uploaded under separate cover
    String attachmentId = msgElem.getAttribute(MailConstants.A_ATTACHMENT_ID, null);
    Element contentElement = msgElem.getOptionalElement(MailConstants.E_CONTENT);
    InviteParserResult ipr = null;
    MimeMessage mm = null;
    if (attachmentId != null) {
        ParseMimeMessage.MimeMessageData mimeData = new ParseMimeMessage.MimeMessageData();
        mm = SendMsg.parseUploadedMessage(zsc, attachmentId, mimeData);
    } else if (contentElement != null) {
        mm = ParseMimeMessage.importMsgSoap(msgElem);
    } else {
        CalSendData dat = handleMsgElement(zsc, octxt, msgElem, acct, mbox, parser);
        mm = dat.mMm;
        ipr = parser.getResult();
    }
    if (ipr == null && msgElem.getOptionalElement(MailConstants.E_INVITE) != null) {
        ipr = parser.parse(zsc, octxt, mbox.getAccount(), msgElem.getElement(MailConstants.E_INVITE));
        // in the <inv> but not in mime parts.
        if (ipr != null && ipr.mInvite != null && mm != null) {
            String desc = Invite.getDescription(mm, MimeConstants.CT_TEXT_PLAIN);
            String descHtml = Invite.getDescription(mm, MimeConstants.CT_TEXT_HTML);
            if ((desc != null && desc.length() > 0) || (descHtml != null && descHtml.length() > 0)) {
                ipr.mInvite.setDescription(desc, descHtml);
            }
        }
    }
    ParsedMessage pm = new ParsedMessage(mm, mbox.attachmentsIndexingEnabled());
    Invite inv = (ipr == null ? null : ipr.mInvite);
    if (inv == null || inv.getDTStamp() == -1) {
        // zdsync if -1 for 4.5 back compat
        CalendarPartInfo cpi = pm.getCalendarPartInfo();
        ZVCalendar cal = null;
        if (cpi != null && CalendarItem.isAcceptableInvite(mbox.getAccount(), cpi)) {
            cal = cpi.cal;
        }
        if (cal == null) {
            throw ServiceException.FAILURE("SetCalendarItem could not build an iCalendar object", null);
        }
        // not applicable in the SetCalendarItem case
        boolean sentByMe = false;
        Invite iCalInv = Invite.createFromCalendar(acct, pm.getFragment(acct.getLocale()), cal, sentByMe).get(0);
        if (inv == null) {
            inv = iCalInv;
        } else {
            // zdsync
            inv.setDtStamp(iCalInv.getDTStamp());
            // zdsync
            inv.setFragment(iCalInv.getFragment());
        }
    }
    inv.setPartStat(partStatStr);
    SetCalendarItemData sadata = new SetCalendarItemData();
    sadata.invite = inv;
    sadata.message = pm;
    return sadata;
}
Also used : ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Element(com.zimbra.common.soap.Element) CalendarPartInfo(com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo) SetCalendarItemData(com.zimbra.cs.mailbox.Mailbox.SetCalendarItemData) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) InviteParserResult(com.zimbra.cs.service.mail.ParseMimeMessage.InviteParserResult) MimeMessage(javax.mail.internet.MimeMessage) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 8 with CalendarPartInfo

use of com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo in project zm-mailbox by Zimbra.

the class Mailbox method addMessage.

private Message addMessage(OperationContext octxt, ParsedMessage pm, int folderId, boolean noICal, int flags, String[] tags, int conversationId, String rcptEmail, Message.DraftInfo dinfo, CustomMetadata customData, DeliveryContext dctxt) throws IOException, ServiceException {
    // and then actually add the message
    long start = ZimbraPerf.STOPWATCH_MBOX_ADD_MSG.start();
    // 
    if (!noICal) {
        try {
            CalendarPartInfo cpi = pm.getCalendarPartInfo();
            if (cpi != null && CalendarItem.isAcceptableInvite(getAccount(), cpi)) {
                if (ICalTok.REPLY.equals(cpi.method)) {
                    processICalReplies(octxt, cpi.cal, null);
                } else if (ICalTok.COUNTER.equals(cpi.method)) {
                    processICalReplies(octxt, cpi.cal, pm.getSender());
                }
            }
        } catch (Exception e) {
            ZimbraLog.calendar.warn("Error during calendar processing.  Continuing with message add", e);
        }
    }
    // Store the incoming blob if necessary.
    if (dctxt == null) {
        dctxt = new DeliveryContext();
    }
    boolean deleteMailboxSpecificBlob = false;
    StoreManager sm = StoreManager.getInstance();
    Blob blob = dctxt.getMailBoxSpecificBlob(mId);
    if (blob == null) {
        blob = dctxt.getIncomingBlob();
        ZimbraLog.filter.debug("MailBoxSpecificBlob is null for mailbox %d", mId);
    } else {
        deleteMailboxSpecificBlob = true;
        ZimbraLog.filter.debug("got MailBoxSpecificBlob for mailbox %d", mId);
    }
    boolean deleteIncoming = false;
    if (blob == null) {
        InputStream in = null;
        try {
            in = pm.getRawInputStream();
            blob = sm.storeIncoming(in);
        } finally {
            ByteUtil.closeStream(in);
        }
        dctxt.setIncomingBlob(blob);
        deleteIncoming = true;
    }
    StagedBlob staged = sm.stage(blob, this);
    Account account = this.getAccount();
    boolean localMsgMarkedRead = false;
    if (account.getPrefMailForwardingAddress() != null && account.isFeatureMailForwardingEnabled() && account.isFeatureMarkMailForwardedAsRead()) {
        ZimbraLog.mailbox.debug("Marking forwarded message as read.");
        flags = flags & ~Flag.BITMASK_UNREAD;
        localMsgMarkedRead = true;
    }
    lock.lock();
    try {
        try {
            Message message = addMessageInternal(octxt, pm, folderId, noICal, flags, tags, conversationId, rcptEmail, dinfo, customData, dctxt, staged);
            if (localMsgMarkedRead && account.getPrefMailSendReadReceipts().isAlways()) {
                SendDeliveryReport.sendReport(account, message, true, null, null);
            }
            return message;
        } finally {
            if (deleteIncoming) {
                sm.quietDelete(dctxt.getIncomingBlob());
            }
            if (deleteMailboxSpecificBlob) {
                sm.quietDelete(dctxt.getMailBoxSpecificBlob(mId));
                dctxt.clearMailBoxSpecificBlob(mId);
            }
            sm.quietDelete(staged);
        }
    } finally {
        lock.release();
        ZimbraPerf.STOPWATCH_MBOX_ADD_MSG.stop(start);
    }
}
Also used : Account(com.zimbra.cs.account.Account) StoreIncomingBlob(com.zimbra.cs.redolog.op.StoreIncomingBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) Blob(com.zimbra.cs.store.Blob) StagedBlob(com.zimbra.cs.store.StagedBlob) ImapMessage(com.zimbra.cs.imap.ImapMessage) Pop3Message(com.zimbra.cs.pop3.Pop3Message) MimeMessage(javax.mail.internet.MimeMessage) CreateMessage(com.zimbra.cs.redolog.op.CreateMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Rfc822ValidationInputStream(com.zimbra.common.mime.Rfc822ValidationInputStream) CopyInputStream(com.zimbra.common.util.CopyInputStream) InputStream(java.io.InputStream) CalendarPartInfo(com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo) AccountServiceException(com.zimbra.cs.account.AccountServiceException) IOException(java.io.IOException) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) ServiceException(com.zimbra.common.service.ServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StoreManager(com.zimbra.cs.store.StoreManager)

Aggregations

CalendarPartInfo (com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo)8 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)7 InputStream (java.io.InputStream)4 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)3 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)3 ServiceException (com.zimbra.common.service.ServiceException)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)3 IOException (java.io.IOException)3 MimeMessage (javax.mail.internet.MimeMessage)3 Test (org.junit.Test)3 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)2 Account (com.zimbra.cs.account.Account)2 ImapMessage (com.zimbra.cs.imap.ImapMessage)2 Pop3Message (com.zimbra.cs.pop3.Pop3Message)2 CreateMessage (com.zimbra.cs.redolog.op.CreateMessage)2 StoreIncomingBlob (com.zimbra.cs.redolog.op.StoreIncomingBlob)2 Blob (com.zimbra.cs.store.Blob)2 MailboxBlob (com.zimbra.cs.store.MailboxBlob)2 StagedBlob (com.zimbra.cs.store.StagedBlob)2