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