MoveItems Event with much items

Add-in Express™ Support Service
That's what is more important than anything else

MoveItems Event with much items
 
Andreas Dobler




Posts: 12
Joined: 2006-05-01
i am using your OlItems_SinkHelper to catch the ItemAdd event of an outlook folder.
if i mark more mails (e.g. 20) and move them to the folder, the event doesn´t get raised.

do you now a solution for that problem?
(i am using outlook2003)

best regards
andreas
Posted 01 Sep, 2006 08:04:19 Top
David Ing




Posts: 56
Joined: 2006-06-27
ItemAdd doesn't fire for 'large' numbers - it's an Outlook (very annoying) bug/restriction, i.e. http://support.microsoft.com/?kbid=249156 (applies to Outlook 2003 too). If the folder is the inbox then you can use the NewMailEx event instead.

As an alternative you could use a MAPIFolder::FolderChange event, but then you have to track the actual folder changes yourself, i.e. remember the last scanned EntryId you looked at (perhaps with a .Restrict/Find) and the go look for 'the marker' item again at the next FolderChange. The new things should be the stuff that caused the FolderChange.
Posted 01 Sep, 2006 10:10:36 Top
Andreas Dobler




Posts: 12
Joined: 2006-05-01
do you have an example?
Posted 04 Sep, 2006 09:59:18 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Andreas.

You can find the OutlookFoldersEvents example in the ADX installation directory.
Posted 05 Sep, 2006 05:44:43 Top
Andreas Dobler




Posts: 12
Joined: 2006-05-01
In your OutlookFoldersEvents example the ProcessFolderChange event is handling the rename folder event. It´s not raised when i add mails to the folder.
In your example OutlookFolderItemsEvents the event ProcessItemAdd is only raised when i move less than 15 mails.

No, the folder is not the Inbox.
Is your ProcessItemAdd event not a encapsulation of a Mapi event?
Posted 05 Sep, 2006 08:46:10 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Andreas, I am working on the MAPI events at the moment.
ADX will support them a bit later in the next ADX builds.
Posted 05 Sep, 2006 08:52:47 Top
Andreas Dobler




Posts: 12
Joined: 2006-05-01
i have seen that you can only connect to 1 folder with your class OutlookFolderItemsEvents.

in my case i must connect to more folders on the same time...
here is the code i am using. maybe you can add these functionality to your solution.

the GetFolderPath methode is not perfect ... i know:

[ClassInterface(ClassInterfaceType.None)]
    public class OlItems_SinkHelper : IFolderItemsEvents, System.IDisposable
    {
        private bool disposed = false;
        private UCOMIConnectionPointContainer oConnPointContainer;
        private UCOMIConnectionPoint m_oConnectionPoint;
        private int m_Cookie;
        private AddinModule owner;

        public delegate void ItemEvent(Outlook.MailItem Item);
        public event ItemEvent itemEvent;

        System.Collections.Hashtable connectedFolders = new System.Collections.Hashtable();
        System.Collections.Hashtable connectedPointers = new System.Collections.Hashtable();

        public OlItems_SinkHelper(AddinModule connect)
        {
            oConnPointContainer = null;
            m_oConnectionPoint = null;
            m_Cookie = 0;
            this.owner = owner;
        }

        ~OlItems_SinkHelper()
        {
            FreeState();
        }

        public void Dispose()
        {
            FreeState();
            GC.SuppressFinalize(this);
        }

        private void FreeState()
        {
            if (!disposed)
            {
                RemoveAll();
                owner = null;
                disposed = true;
            }
        }

        public bool ConnectTo(Outlook.MAPIFolder folder)
        {
            //if (m_Cookie != 0) return false;
            try
            {
                Guid guid = new Guid("{00063077-0000-0000-C000-000000000046}");
                oConnPointContainer = (UCOMIConnectionPointContainer)folder.Items;
                oConnPointContainer.FindConnectionPoint(ref guid, out m_oConnectionPoint);
                if (m_oConnectionPoint != null)
                {
                    m_oConnectionPoint.Advise(this, out m_Cookie);
                    connectedFolders.Add(GetFolderPath(folder), m_Cookie);
                    connectedPointers.Add(GetFolderPath(folder), folder);
                }
            }
            catch
            {
                return false;
            }
            return true;
        }

        public void RemoveConnection(Outlook.MAPIFolder folder)
        {
            try
            {
                if (folder != null)
                {
                    Guid guid = new Guid("{00063077-0000-0000-C000-000000000046}");
                    oConnPointContainer = (UCOMIConnectionPointContainer)folder.Items;
                    oConnPointContainer.FindConnectionPoint(ref guid, out m_oConnectionPoint);
                    if (m_oConnectionPoint != null)
                    {
                        m_Cookie = (int)connectedFolders[GetFolderPath(folder)];
                        m_oConnectionPoint.Unadvise(m_Cookie);
                    }
                    Marshal.ReleaseComObject(m_oConnectionPoint);
                    Marshal.ReleaseComObject(oConnPointContainer);
                    m_Cookie = 0;
                    connectedPointers.Remove(GetFolderPath(folder));
                    connectedFolders.Remove(GetFolderPath(folder));
                }
            }
            catch
            {
            }
        }

        private string GetFolderPath(Outlook.MAPIFolder folder)
        {

            Outlook.Application OutlookApp = folder.Application;

            if (OutlookApp.Version.Substring(0, 3) != "9.0")
                return folder.FullFolderPath;
            else
            {
                string path = "\\";
                System.Collections.ArrayList folderNames = new System.Collections.ArrayList();
                folderNames.Add(folder.Name);
                while (folder.Parent != null)
                {
                    try
                    {
                        folder = (Outlook.MAPIFolder)folder.Parent;
                        folderNames.Add(folder.Name);
                    }
                    catch
                    {
                        break;
                    }
                }
                for (int i = 0; i < folderNames.Count; i++)
                {
                    path += (string)folderNames[folderNames.Count - i - 1] + "\";
                }
                return path.Substring(0, path.Length - 1);
            }
        }


        public void RemoveAll()
        {
            try
            {
                Guid guid = new Guid("{00063077-0000-0000-C000-000000000046}");
                for (int i = 0; i < connectedFolders.Count; i++ )
                {
                    Outlook.MAPIFolder folder = (Outlook.MAPIFolder)connectedPointers[i];
                    m_Cookie = (int)connectedFolders[i];
                    oConnPointContainer = (UCOMIConnectionPointContainer)folder.Items;
                    oConnPointContainer.FindConnectionPoint(ref guid, out m_oConnectionPoint);
                    if (m_oConnectionPoint != null)
                    {
                        m_oConnectionPoint.Unadvise(m_Cookie);
                    }
                }
                connectedFolders.Clear();
                connectedPointers.Clear();
            }
            catch
            {
            }
        }

        public void ItemAdd(object Item)
        {
            Marshal.ReleaseComObject(Item);
        }

        public void ItemChange(object Item)
        {
            Marshal.ReleaseComObject(Item);
        }

        public void ItemRemove()
        {
        }
    }
Posted 05 Sep, 2006 09:04:04 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Andreas, thank you for the code. I will try to implement it.
Posted 05 Sep, 2006 09:17:29 Top