'---------------------------------------------------------------------------------------
' Procédure : GetConversationsFolders
' Auteur : Mickaël
' Date : 23/06/2021
' Sujet : Cette procédure est utilisée pour, à partir d'un dossier Outlook, extraire toutes
' les 'ConversationID' des mails avec les dossier dans lesquels ces conversation ont
' été trouvées.
' Pour la recherche d'éléments, cette procédure utilise la fonction GetFoldersPerConversationID.
' Retourne : Scripting.Dictionary
' - clef : ConversationID
' - valeur : VBA.Collection de 1 ou plusieurs Outlook.Folder
' Pàaramètres :
' - p_o_folder (Outlook.Folder) : dossier de stockage des mails
'---------------------------------------------------------------------------------------
'
Public Function GetConversationsFolders(p_o_folder As Outlook.Folder) As Object 'Scripting.Dictionary
Dim l_o_dicoRes As Object 'Scripting.Dictionary
Dim l_o_dicoConversations As Object 'Scripting.Dictionary
Dim l_o_dicoFolders As Object 'Scripting.Dictionary
Dim l_av_convKeys() As Variant
Dim l_av_convDicos() As Variant
Dim l_o_collConv As VBA.Collection
Dim l_l_iConv As Long
Dim l_av_folders() As Variant
Dim l_l_iFold As Long
Set l_o_dicoRes = CreateObject("Scripting.Dictionary")
Set l_o_dicoConversations = GetFoldersPerConversationID(p_o_folder)
l_av_convKeys = l_o_dicoConversations.Keys()
l_av_convDicos = l_o_dicoConversations.Items()
For l_l_iConv = 0 To l_o_dicoConversations.Count - 1
Set l_o_collConv = New VBA.Collection
Set l_o_dicoFolders = l_av_convDicos(l_l_iConv)
l_av_folders = l_o_dicoFolders.Items()
For l_l_iFold = 0 To l_o_dicoFolders.Count - 1
l_o_collConv.Add l_av_folders(l_l_iFold)
Next l_l_iFold
l_o_dicoRes.Add l_av_convKeys(l_l_iConv), l_o_collConv
Next l_l_iConv
Set GetConversationsFolders = l_o_dicoRes
Set l_o_dicoRes = Nothing
Set l_o_dicoConversations = Nothing
Set l_o_dicoFolders = Nothing
Set l_o_collConv = Nothing
End Function
'Private Function GetFoldersPerConversationID(p_o_folder As Outlook.Folder, Optional p_o_dicoRes As Scripting.Dictionary = Nothing) As Scripting.Dictionary
Private Function GetFoldersPerConversationID(p_o_folder As Outlook.Folder, Optional p_o_dicoRes As Object = Nothing) As Object
Dim l_o_subFolder As Outlook.Folder
Dim l_o_item As Object
Dim l_o_mailItem As Outlook.MailItem
Dim l_o_dicoFolders As Object 'Scripting.Dictionary
If p_o_dicoRes Is Nothing Then Set p_o_dicoRes = CreateObject("Scripting.Dictionary")
For Each l_o_item In p_o_folder.Items
If TypeOf l_o_item Is MailItem Then
Set l_o_mailItem = l_o_item
If Not p_o_dicoRes.Exists(l_o_mailItem.ConversationID) Then p_o_dicoRes.Add l_o_mailItem.ConversationID, CreateObject("Scripting.Dictionary")
Set l_o_dicoFolders = p_o_dicoRes.Item(l_o_mailItem.ConversationID)
If Not l_o_dicoFolders.Exists(p_o_folder.FolderPath) Then l_o_dicoFolders.Add p_o_folder.FolderPath, p_o_folder
End If
Next l_o_item
For Each l_o_subFolder In p_o_folder.Folders
GetFoldersPerConversationID l_o_subFolder, p_o_dicoRes
Next l_o_subFolder
Set GetFoldersPerConversationID = p_o_dicoRes
Set l_o_subFolder = Nothing
Set l_o_item = Nothing
Set l_o_mailItem = Nothing
Set l_o_dicoFolders = Nothing
End Function