예제 #1
0
        internal static void ReplaceAttachmentContent(string smtpAddress, string cultureName, string ewsAttachmentID, bool isArchive, Stream source)
        {
            ADSessionSettings   adsessionSettings;
            ExchangePrincipal   exchangePrincipal   = WacUtilities.GetExchangePrincipal(smtpAddress, out adsessionSettings, isArchive);
            CultureInfo         cultureInfo         = CultureInfo.GetCultureInfo(cultureName);
            List <AttachmentId> attachmentIds       = new List <AttachmentId>();
            IdHeaderInformation idHeaderInformation = ServiceIdConverter.ConvertFromConcatenatedId(ewsAttachmentID, BasicTypes.Attachment, attachmentIds);

            idHeaderInformation.ToStoreObjectId();
            using (MailboxSession mailboxSession = MailboxSession.OpenAsSystemService(exchangePrincipal, cultureInfo, "Client=OWA;Action=WAC"))
            {
                WacUtilities.ProcessAttachment(mailboxSession, ewsAttachmentID, exchangePrincipal, PropertyOpenMode.Modify, delegate(IExchangePrincipal principal, Attachment attachment, Stream stream, bool anyContentProtected)
                {
                    BinaryReader binaryReader = new BinaryReader(source);
                    stream.Seek(0L, SeekOrigin.Begin);
                    int num       = 10000;
                    int num2      = 0;
                    byte[] buffer = new byte[num];
                    for (;;)
                    {
                        int num3 = binaryReader.Read(buffer, 0, num);
                        num2    += num3;
                        if (num3 == 0)
                        {
                            break;
                        }
                        stream.Write(buffer, 0, num3);
                    }
                    stream.SetLength((long)num2);
                    attachment.Save();
                });
            }
        }
예제 #2
0
        private static void ProcessAttachment(WacRequest wacRequest, PropertyOpenMode openMode, WacUtilities.AttachmentProcessor attachmentProcessor)
        {
            ADSessionSettings adSessionSettings;
            ExchangePrincipal exchangePrincipal = WacUtilities.GetExchangePrincipal(wacRequest, out adSessionSettings, wacRequest.WacFileRep.IsArchive);

            WacRequestHandler.ProcessUsingBudget(wacRequest.WacFileRep.LogonSid, delegate
            {
                string ewsAttachmentId  = wacRequest.EwsAttachmentId;
                CultureInfo cultureInfo = CultureInfo.GetCultureInfo(wacRequest.CultureName);
                string clientInfoString = "Client=OWA;Action=WAC";
                if (exchangePrincipal.RecipientTypeDetails.HasFlag(RecipientTypeDetails.PublicFolder) || exchangePrincipal.RecipientTypeDetails.HasFlag(RecipientTypeDetails.PublicFolderMailbox))
                {
                    using (PublicFolderSession publicFolderSession = PublicFolderSession.OpenAsAdmin(null, exchangePrincipal, null, cultureInfo, clientInfoString, null))
                    {
                        WacUtilities.ProcessAttachment(publicFolderSession, ewsAttachmentId, exchangePrincipal, openMode, attachmentProcessor);
                        return;
                    }
                }
                using (MailboxSession mailboxSession = MailboxSession.OpenAsSystemService(exchangePrincipal, cultureInfo, clientInfoString))
                {
                    WacUtilities.ProcessAttachment(mailboxSession, ewsAttachmentId, exchangePrincipal, openMode, attachmentProcessor);
                }
            }, adSessionSettings);
        }