Search in sources :

Example 1 with CalendarPartInfo

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

the class ZAttendeeTest method resourceRsvpTest3.

@Test
public void resourceRsvpTest3() throws Exception {
    InputStream is = getClass().getResourceAsStream("Calendar_NewMeetingRequest_RsvpFalse.txt");
    ParsedMessage pm = new ParsedMessage(ByteUtil.getContent(is, -1), false);
    CalendarPartInfo cpi = pm.getCalendarPartInfo();
    Iterator<ZComponent> compIter = cpi.cal.getComponentIterator();
    while (compIter.hasNext()) {
        ZComponent comp = compIter.next();
        List<ZProperty> properties = Lists.newArrayList(comp.getPropertyIterator());
        for (ZProperty prop : properties) {
            if (prop.getName().equalsIgnoreCase("ATTENDEE")) {
                ZAttendee attendee = new ZAttendee(prop);
                Assert.assertFalse(attendee.getRsvp());
            }
        }
    }
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) InputStream(java.io.InputStream) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) CalendarPartInfo(com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo) Test(org.junit.Test)

Example 2 with CalendarPartInfo

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

the class ZAttendeeTest method resourceRsvpTest2.

@Test
public void resourceRsvpTest2() throws ServiceException, IOException {
    InputStream is = getClass().getResourceAsStream("Calendar_NewMeetingRequest_RsvpTrue.txt");
    ParsedMessage pm = new ParsedMessage(ByteUtil.getContent(is, -1), false);
    CalendarPartInfo cpi = pm.getCalendarPartInfo();
    Iterator<ZComponent> compIter = cpi.cal.getComponentIterator();
    while (compIter.hasNext()) {
        ZComponent comp = compIter.next();
        List<ZProperty> properties = Lists.newArrayList(comp.getPropertyIterator());
        for (ZProperty prop : properties) {
            if (prop.getName().equalsIgnoreCase("ATTENDEE")) {
                ZAttendee attendee = new ZAttendee(prop);
                Assert.assertTrue(attendee.getRsvp());
            }
        }
    }
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) InputStream(java.io.InputStream) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) CalendarPartInfo(com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo) Test(org.junit.Test)

Example 3 with CalendarPartInfo

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

the class ZAttendeeTest method resourceRsvpTest4.

@Test
public void resourceRsvpTest4() throws Exception {
    InputStream is = getClass().getResourceAsStream("Calendar_ChangeMeetingRequest_WO_Rsvp.txt");
    ParsedMessage pm = new ParsedMessage(ByteUtil.getContent(is, -1), false);
    CalendarPartInfo cpi = pm.getCalendarPartInfo();
    Iterator<ZComponent> compIter = cpi.cal.getComponentIterator();
    while (compIter.hasNext()) {
        ZComponent comp = compIter.next();
        List<ZProperty> properties = Lists.newArrayList(comp.getPropertyIterator());
        for (ZProperty prop : properties) {
            if (prop.getName().equalsIgnoreCase("ATTENDEE")) {
                ZAttendee attendee = new ZAttendee(prop);
                Assert.assertNull(attendee.getRsvp());
            }
        }
    }
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) InputStream(java.io.InputStream) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) CalendarPartInfo(com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo) Test(org.junit.Test)

Example 4 with CalendarPartInfo

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

the class InviteTest method executeBasic.

/**
 * Returns <tt>true</tt> if the message has a calendar part.
 */
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) {
    if (mail instanceof DummyMailAdapter) {
        return true;
    }
    if (!(mail instanceof ZimbraMailAdapter)) {
        return false;
    }
    ParsedMessage pm = ((ZimbraMailAdapter) mail).getParsedMessage();
    if (pm == null) {
        return false;
    }
    CalendarPartInfo calPart = pm.getCalendarPartInfo();
    if (calPart != null) {
        if (mMethods.isEmpty()) {
            // Test matches any invite.
            return true;
        }
        if (calPart.method == null) {
            // Method not specified in the calendar part.
            return false;
        }
        if (mMethods.contains(calPart.method.toString())) {
            // Calendar part method matches one of the methods in the test.
            return true;
        }
        if (mMethods.contains("anyrequest") && isRequest(calPart.method)) {
            return true;
        }
        if (mMethods.contains("anyreply") && isReply(calPart.method)) {
            return true;
        }
    }
    return false;
}
Also used : ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) CalendarPartInfo(com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Example 5 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