示例#1
0
 protected static void CreateAndSubmitMessage(MapiFolder folder, string sourceMailboxName, string targetMailAddress, string subject, bool deleteAfterSubmit)
 {
     using (MapiMessage mapiMessage = folder.CreateMessage())
     {
         PropValue[] props = new PropValue[]
         {
             new PropValue(PropTag.DeleteAfterSubmit, deleteAfterSubmit),
             new PropValue(PropTag.Subject, subject),
             new PropValue(PropTag.ReceivedByEmailAddress, targetMailAddress),
             new PropValue(PropTag.Body, "This is a Test-Mailflow probe message.")
         };
         mapiMessage.SetProps(props);
         mapiMessage.ModifyRecipients(ModifyRecipientsFlags.AddRecipients, new AdrEntry[]
         {
             new AdrEntry(new PropValue[]
             {
                 new PropValue(PropTag.EmailAddress, targetMailAddress),
                 new PropValue(PropTag.OriginatorDeliveryReportRequested, deleteAfterSubmit),
                 new PropValue(PropTag.AddrType, "SMTP"),
                 new PropValue(PropTag.RecipientType, RecipientType.To),
                 new PropValue(PropTag.DisplayName, sourceMailboxName)
             })
         });
         mapiMessage.SaveChanges();
         mapiMessage.SubmitMessage(SubmitMessageFlags.ForceSubmit);
     }
 }
示例#2
0
        private uint CreateMsgWithAttachement(out byte[] entryId)
        {
            ASCIIEncoding asciiencoding = new ASCIIEncoding();
            uint          @int;

            using (MapiMessage mapiMessage = this.testFolder.CreateMessage())
            {
                PropValue[] props = new PropValue[]
                {
                    new PropValue(PropTag.Subject, string.Format("CITestSearch: {0}.", this.searchString)),
                    new PropValue(PropTag.Body, string.Format("The unique search string in the body is: {0}.", this.searchString)),
                    new PropValue(PropTag.MessageDeliveryTime, (DateTime)ExDateTime.Now)
                };
                this.threadExit.CheckStop();
                mapiMessage.SetProps(props);
                int num;
                using (MapiAttach mapiAttach = mapiMessage.CreateAttach(out num))
                {
                    string s     = string.Format("This is a test msg created by test-search task (MSExchangeSearch {0}).It will be deleted soon...", this.searchString);
                    byte[] bytes = asciiencoding.GetBytes(s);
                    using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.Create))
                    {
                        mapiStream.Write(bytes, 0, bytes.Length);
                        mapiStream.Flush();
                        this.threadExit.CheckStop();
                    }
                    props = new PropValue[]
                    {
                        new PropValue(PropTag.AttachFileName, "CITestSearch.txt"),
                        new PropValue(PropTag.AttachMethod, AttachMethods.ByValue)
                    };
                    mapiAttach.SetProps(props);
                    mapiAttach.SaveChanges();
                }
                this.threadExit.CheckStop();
                mapiMessage.SaveChanges();
                entryId = mapiMessage.GetProp(PropTag.EntryId).GetBytes();
                @int    = (uint)mapiMessage.GetProp(PropTag.DocumentId).GetInt();
            }
            return(@int);
        }
示例#3
0
        public PersistablePropertyBag CreateAttachment(ICollection <PropertyDefinition> propertiesToLoad, CoreAttachment attachmentToClone, IItem itemToAttach, out int attachmentNumber)
        {
            MapiAttach             mapiAttach             = null;
            PersistablePropertyBag persistablePropertyBag = null;
            bool flag = false;
            int  num  = 0;

            try
            {
                StoreSession session = this.AttachmentCollection.ContainerItem.Session;
                bool         flag2   = false;
                try
                {
                    if (session != null)
                    {
                        session.BeginMapiCall();
                        session.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    mapiAttach = this.AttachmentCollection.ContainerItem.MapiMessage.CreateAttach(out num);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex, session, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex2, session, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (session != null)
                        {
                            session.EndMapiCall();
                            if (flag2)
                            {
                                session.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                attachmentNumber = num;
                if (attachmentToClone != null)
                {
                    MapiAttachmentProvider.CopySavedMapiAttachment(true, this, this.AttachmentCollection.ContainerItem.Session, (MapiAttach)attachmentToClone.PropertyBag.MapiProp, mapiAttach);
                }
                else if (itemToAttach != null)
                {
                    MapiMessage  mapiMessage  = itemToAttach.MapiMessage;
                    MapiMessage  mapiMessage2 = null;
                    StoreSession session2     = this.AttachmentCollection.ContainerItem.Session;
                    bool         flag3        = false;
                    try
                    {
                        if (session2 != null)
                        {
                            session2.BeginMapiCall();
                            session2.BeginServerHealthCall();
                            flag3 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        mapiMessage2 = mapiAttach.OpenEmbeddedMessage(OpenPropertyFlags.Create);
                    }
                    catch (MapiPermanentException ex3)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex3, session2, this, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                            ex3
                        });
                    }
                    catch (MapiRetryableException ex4)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex4, session2, this, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                            ex4
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session2 != null)
                            {
                                session2.EndMapiCall();
                                if (flag3)
                                {
                                    session2.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                    using (mapiMessage2)
                    {
                        PropProblem[] array    = null;
                        StoreSession  session3 = this.AttachmentCollection.ContainerItem.Session;
                        bool          flag4    = false;
                        try
                        {
                            if (session3 != null)
                            {
                                session3.BeginMapiCall();
                                session3.BeginServerHealthCall();
                                flag4 = true;
                            }
                            if (StorageGlobals.MapiTestHookBeforeCall != null)
                            {
                                StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                            }
                            array = mapiMessage.CopyTo(mapiMessage2, new PropTag[]
                            {
                                (PropTag)InternalSchema.UrlCompName.PropertyTag
                            });
                        }
                        catch (MapiPermanentException ex5)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCopyFailedProperties, ex5, session3, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                                ex5
                            });
                        }
                        catch (MapiRetryableException ex6)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCopyFailedProperties, ex6, session3, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                                ex6
                            });
                        }
                        finally
                        {
                            try
                            {
                                if (session3 != null)
                                {
                                    session3.EndMapiCall();
                                    if (flag4)
                                    {
                                        session3.EndServerHealthCall();
                                    }
                                }
                            }
                            finally
                            {
                                if (StorageGlobals.MapiTestHookAfterCall != null)
                                {
                                    StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                                }
                            }
                        }
                        if (array != null)
                        {
                            int num2 = -1;
                            for (int i = 0; i < array.Length; i++)
                            {
                                int scode = array[i].Scode;
                                if (scode == -2147221233 || scode == -2147221222)
                                {
                                    ExTraceGlobals.StorageTracer.TraceDebug <int>((long)this.GetHashCode(), "Storage.MapiAttachmentProvider.AddExisting Item: CopyTo returned ignorable scode = {0}", scode);
                                }
                                else
                                {
                                    ExTraceGlobals.StorageTracer.TraceError <int>((long)this.GetHashCode(), "Storage.MapiAttachmentProvider.AddExisting Item: CopyTo returned fatal scode = {0}", scode);
                                    num2 = i;
                                }
                                if (num2 != -1)
                                {
                                    throw PropertyError.ToException(ServerStrings.ExUnableToCopyAttachments, StoreObjectPropertyBag.MapiPropProblemsToPropertyErrors(null, mapiMessage, array));
                                }
                            }
                        }
                        StoreSession session4 = this.AttachmentCollection.ContainerItem.Session;
                        bool         flag5    = false;
                        try
                        {
                            if (session4 != null)
                            {
                                session4.BeginMapiCall();
                                session4.BeginServerHealthCall();
                                flag5 = true;
                            }
                            if (StorageGlobals.MapiTestHookBeforeCall != null)
                            {
                                StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                            }
                            mapiMessage2.SaveChanges();
                        }
                        catch (MapiPermanentException ex7)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSaveChanges, ex7, session4, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                                ex7
                            });
                        }
                        catch (MapiRetryableException ex8)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSaveChanges, ex8, session4, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                                ex8
                            });
                        }
                        finally
                        {
                            try
                            {
                                if (session4 != null)
                                {
                                    session4.EndMapiCall();
                                    if (flag5)
                                    {
                                        session4.EndServerHealthCall();
                                    }
                                }
                            }
                            finally
                            {
                                if (StorageGlobals.MapiTestHookAfterCall != null)
                                {
                                    StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                                }
                            }
                        }
                    }
                }
                persistablePropertyBag            = this.CreateStorePropertyBag(mapiAttach, propertiesToLoad);
                persistablePropertyBag.ExTimeZone = this.ExTimeZone;
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                    }
                    if (mapiAttach != null)
                    {
                        mapiAttach.Dispose();
                    }
                }
            }
            return(persistablePropertyBag);
        }