VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Class1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public WithEvents OutlookApplication As Outlook.Application
Attribute OutlookApplication.VB_VarHelpID = -1

Sub Initialize_Handler()
  Set OutlookApplication = Application
End Sub

Public Sub OutlookApplication_NewEmailEx(ByVal EntryIDCollection As String)
  Debug.Print Now & " OutlookApplication_NewEmailEx(" & EntryIDCollection & ")"
  
  If EntryIDCollection = "INIT" Then Exit Sub
  
  Dim objOutlookNameSpace As Outlook.NameSpace
  Dim objOutlookMailApp   As MailItem
  Dim objOutlookMailItem  As Outlook.MailItem
  Dim strEntryIDValue()   As String
  Dim intEntryIDIndex     As Integer
  
  On Error Resume Next
  Set objOutlookNameSpace = Application.Session
  
  strEntryIDValue = Split(EntryIDCollection, ",")
  
  For intEntryIDIndex = 0 To UBound(strEntryIDValue)
    Set objOutlookMailApp = objOutlookNameSpace.GetItemFromID(strEntryIDValue(intEntryIDIndex))
    
    If objOutlookMailApp.Class = olMail Then
      Set objOutlookMailItem = objOutlookMailApp
      
      Debug.Print Now & " " & objOutlookMailItem.Sender & " " & _
                        "(" & objOutlookMailItem.SenderName & ") " & _
                        "[" & objOutlookMailItem.SenderEmailAddress & "]"
      Debug.Print Now & " " & objOutlookMailItem.Subject
      
      Form1.List1.AddItem objOutlookMailItem.Sender
      Form1.List2.AddItem objOutlookMailItem.SenderName
      Form1.List3.AddItem objOutlookMailItem.SenderEmailAddress
      Form1.List4.AddItem objOutlookMailItem.Subject
    End If
  Next
  
  Set objOutlookNameSpace = Nothing
  Set objOutlookMailApp = Nothing
  Set objOutlookMailItem = Nothing
  
  Exit Sub
  
  'Dim objEmailObject   As Object
  'Dim intEntryIDStart  As Integer
  'Dim intEntryIDEnd    As Integer
  'Dim strEntryIDValue  As String
  'Dim intEntryIDLength As Integer
  
  'intEntryIDStart = 1
  'intEntryIDLength = Len(EntryIDCollection)
  
  'Label5.Caption = "Collection of EntryIDs: " & EntryIDCollection
  
  'intEntryIDEnd = InStr(intEntryIDStart, EntryIDCollection, ",")
  
  'Do While intEntryIDEnd <> 0
  '  strEntryIDValue = Strings.Mid(EntryIDCollection, intEntryIDStart, (intEntryIDEnd - intEntryIDStart))
    
  '  List1.AddItem strEntryIDValue
    
  '  Set objEmailObject = Application.Session.GetItemFromID(strEntryIDValue)
    
  '  List2.AddItem objEmailObject
    
  '  intEntryIDStart = intEntryIDEnd + 1
  '  intEntryIDEnd = InStr(intEntryIDStart, EntryIDCollection, ",")
  'Loop
  
  'strEntryIDValue = Strings.Mid(EntryIDCollection, intEntryIDStart, (intEntryIDLength - intEntryIDStart) + 1)
  
  'List3.AddItem strEntryIDValue
  
  'Set objEmailObject = Application.Session.GetItemFromID(strEntryIDValue)
  
  'List4.AddItem objEmailObject
End Sub

