示例#1
0
 public static bool TryGetSendAsSubscription(MessageItem item, SendAsManager sendAsManager, out ISendAsSource subscription)
 {
     return(StoreProvider.StoreProviderInstance.TryGetSendAsSubscription(item, sendAsManager, out subscription));
 }
示例#2
0
        public bool TryGetSendAsSubscription(MessageItem item, SendAsManager sendAsManager, out ISendAsSource subscription)
        {
            subscription = null;
            MailboxSession mailboxSession = item.Session as MailboxSession;
            object         obj            = item.TryGetProperty(MessageItemSchema.SharingInstanceGuid);

            if (PropertyError.IsPropertyNotFound(obj))
            {
                if (mailboxSession != null && mailboxSession.MailboxOwner != null && mailboxSession.MailboxOwner.MailboxInfo.IsAggregated)
                {
                    TraceHelper.MapiStoreDriverSubmissionTracer.TracePass(TraceHelper.MessageProbeActivityId, 0L, "The message was submitted from an aggregated mailbox. There must be one associated send as subscription.");
                    bool flag;
                    if (!sendAsManager.TryGetSendAsSubscription(mailboxSession, out subscription, out flag))
                    {
                        TraceHelper.MapiStoreDriverSubmissionTracer.TraceFail(TraceHelper.MessageProbeActivityId, 0L, "Could not find a unique send as subscription.  Rejecting the message.");
                        if (flag)
                        {
                            throw new SmtpResponseException(AckReason.AmbiguousSubscription);
                        }
                        throw new SmtpResponseException(AckReason.SubscriptionNotFound);
                    }
                }
            }
            else
            {
                TraceHelper.MapiStoreDriverSubmissionTracer.TracePass(TraceHelper.MessageProbeActivityId, 0L, "The message has a subscription id on it. Subscription id: {0}", new object[]
                {
                    obj
                });
                if (mailboxSession == null)
                {
                    TraceHelper.MapiStoreDriverSubmissionTracer.TraceFail <Type>(TraceHelper.MessageProbeActivityId, 0L, "The session is not the right type. Actual type: {0}", item.Session.GetType());
                    throw new SmtpResponseException(AckReason.UnrecognizedSendAsMessage);
                }
                if (!sendAsManager.TryGetSendAsSubscription(item, mailboxSession, out subscription))
                {
                    TraceHelper.MapiStoreDriverSubmissionTracer.TraceFail(TraceHelper.MessageProbeActivityId, 0L, "The subscription could not be found. Rejecting the message. Subscription id: {0}", new object[]
                    {
                        obj
                    });
                    throw new SmtpResponseException(AckReason.SubscriptionNotFound);
                }
                if (!sendAsManager.IsSubscriptionEnabled(subscription))
                {
                    TraceHelper.MapiStoreDriverSubmissionTracer.TraceFail(TraceHelper.MessageProbeActivityId, 0L, "The subscription is not enabled. Rejecting the message. Subscription id: {0}", new object[]
                    {
                        obj
                    });
                    throw new SmtpResponseException(AckReason.SubscriptionDisabled);
                }
                if (!sendAsManager.IsSendAsEnabled(subscription))
                {
                    TraceHelper.MapiStoreDriverSubmissionTracer.TraceFail(TraceHelper.MessageProbeActivityId, 0L, "The subscription is not enabled for send as. Rejecting the message. Subscription id: {0}", new object[]
                    {
                        obj
                    });
                    throw new SmtpResponseException(AckReason.SubscriptionNotEnabledForSendAs);
                }
                if (!sendAsManager.IsValidSendAsMessage(subscription, item))
                {
                    TraceHelper.MapiStoreDriverSubmissionTracer.TraceFail(TraceHelper.MessageProbeActivityId, 0L, "The message does not have valid sent representing properties. Rejecting the message. Subscription id: {0}", new object[]
                    {
                        obj
                    });
                    throw new SmtpResponseException(AckReason.InvalidSendAsProperties);
                }
            }
            return(subscription != null);
        }