Esempio n. 1
0
 public ISyncObject GetSyncObject()
 {
     using (ComRelease com = new ComRelease())
     {
         NSOutlook.NameSpace   session     = com.Add(_app.Session);
         NSOutlook.SyncObjects syncObjects = com.Add(session.SyncObjects);
         return(new SyncObjectWrapper(syncObjects.AppFolders));
     }
 }
 public void RemoveStore(IStore store)
 {
     using (store)
         using (ComRelease com = new ComRelease())
         {
             NSOutlook.NameSpace  session    = com.Add(_item.Session);
             NSOutlook.MAPIFolder rootFolder = com.Add(((FolderWrapper)store.GetRootFolder()).RawItem);
             session.RemoveStore(rootFolder);
         }
 }
Esempio n. 3
0
        unsafe public void SetAccountProp(PropTag propTag, object value)
        {
            // Use IOlkAccount to notify while we're running
            // IOlkAccount can only be accessed on main thread
            Logger.Instance.Trace(this, "SetAccountProp1: {0}: {1}", propTag, value);
            ThisAddIn.Instance.InUI(() =>
            {
                Logger.Instance.Trace(this, "SetAccountProp2: {0}: {1}", propTag, value);
                using (ComRelease com = new ComRelease())
                {
                    Logger.Instance.Trace(this, "SetAccountProp3: {0}: {1}", propTag, value);
                    NSOutlook.Account account = com.Add(FindAccountObject());
                    IOlkAccount olk           = com.Add(account.IOlkAccount);
                    Logger.Instance.Trace(this, "SetAccountProp4: {0}: {1}", propTag, value);

                    switch (propTag.type)
                    {
                    case PropType.UNICODE:
                        Logger.Instance.Trace(this, "SetAccountProp5: {0}: {1}", propTag, value);
                        using (MapiAlloc mem = MapiAlloc.FromString((string)value))
                        {
                            ACCT_VARIANT val = new ACCT_VARIANT()
                            {
                                dwType = (uint)PropType.UNICODE,
                                lpszW  = (char *)mem.Ptr
                            };
                            Logger.Instance.Trace(this, "SetAccountProp5A: {0}: {1}", propTag, value);
                            olk.SetProp(propTag, &val);
                            Logger.Instance.Trace(this, "SetAccountProp6: {0}: {1}", propTag, value);
                            olk.SaveChanges(0);
                            Logger.Instance.Trace(this, "SetAccountProp7: {0}: {1}", propTag, value);
                        }
                        break;

                    case PropType.LONG:
                        {
                            Logger.Instance.Trace(this, "SetAccountProp8: {0}: {1}", propTag, value);
                            ACCT_VARIANT val = new ACCT_VARIANT()
                            {
                                dwType = (uint)PropType.LONG,
                                dw     = (uint)value
                            };
                            olk.SetProp(propTag, &val);
                            Logger.Instance.Trace(this, "SetAccountProp9: {0}: {1}", propTag, value);
                            olk.SaveChanges(0);
                            Logger.Instance.Trace(this, "SetAccountPropA: {0}: {1}", propTag, value);
                            break;
                        }
                    }
                    Logger.Instance.Trace(this, "SetAccountPropDone: {0}: {1}", propTag, value);
                }
            }, true);
        }
Esempio n. 4
0
 public IRecipient ResolveRecipient(string name)
 {
     using (ComRelease com = new ComRelease())
     {
         NSOutlook.NameSpace session = com.Add(_app.Session);
         // Add recipient, unlock after Resolve (which might throw) to wrap
         NSOutlook.Recipient recipient = com.Add(session.CreateRecipient(name));
         if (recipient == null)
         {
             return(null);
         }
         IRecipient wrapped = Mapping.Wrap(com.Remove(recipient));
         wrapped.Resolve();
         return(wrapped);
     }
 }
Esempio n. 5
0
 public IFolder GetFolderFromID(string folderId)
 {
     using (ComRelease com = new ComRelease())
     {
         NSOutlook.NameSpace nmspace = com.Add(_app.Session);
         NSOutlook.Folder    f       = (NSOutlook.Folder)nmspace.GetFolderFromID(folderId);
         return(Mapping.Wrap <IFolder>(f));
     }
 }
Esempio n. 6
0
 private NSOutlook.Account FindAccountObject()
 {
     using (ComRelease com = new ComRelease())
     {
         NSOutlook.NameSpace session = com.Add(_item.Session);
         foreach (NSOutlook.Account account in session.Accounts.ComEnum(false))
         {
             if (account.SmtpAddress == this.SmtpAddress)
             {
                 return(account);
             }
             else
             {
                 com.Add(account);
             }
         }
     }
     return(null);
 }
Esempio n. 7
0
        public IItem GetItemFromID(string id)
        {
            using (ComRelease com = new ComRelease())
            {
                NSOutlook.NameSpace nmspace = com.Add(_item.Session);

                // Get the item; the wrapper manages it
                object o = nmspace.GetItemFromID(id);
                return(Mapping.Wrap <IItem>(o));
            }
        }
        public IStore AddFileStore(string path)
        {
            using (ComRelease com = new ComRelease())
            {
                NSOutlook.NameSpace session = com.Add(_item.Session);

                // Add the store
                session.AddStore(path);

                // And fetch it and wrap
                return(Mapping.Wrap(_item[_item.Count]));
            }
        }
Esempio n. 9
0
        public void EmptyDeletedItems()
        {
            using (ComRelease com = new ComRelease())
            {
                NSOutlook.MAPIFolder f = _item.GetDefaultFolder(NSOutlook.OlDefaultFolders.olFolderDeletedItems);
                if (f != null)
                {
                    com.Add(f);

                    // Normal enumeration fails when deleting. Do it like this.
                    NSOutlook.Folders folders = com.Add(f.Folders);
                    for (int i = folders.Count; i > 0; --i)
                    {
                        com.Add(folders[i]).Delete();
                    }

                    NSOutlook.Items items = com.Add(f.Items);
                    for (int i = items.Count; i > 0; --i)
                    {
                        com.Add(items[i]).Delete();
                    }
                }
            }
        }