-
Notifications
You must be signed in to change notification settings - Fork 0
/
CategoryUtil.bas
126 lines (111 loc) · 4.66 KB
/
CategoryUtil.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Attribute VB_Name = "CategoryUtil"
'--------------------------------------------------------------------
' Merge to category strings
' "a;b;c;d" + "c;d;e;f" => "a;b;c;d;e;f"
'--------------------------------------------------------------------
Public Function MergeCategories(cats1 As String, cats2 As String) As String
Dim cats() As String
cats = Split("", ";") ' create an empty array of 0 length
Dim found As Boolean
For Each c1 In Split(cats1, ";")
found = False
For Each c2 In cats
If c2 = c1 Then
found = True
End If
Next c2
If Not found Then
ReDim Preserve cats(0 To UBound(cats) + 1)
cats(UBound(cats)) = c1
End If
Next c1
For Each c2 In Split(cats2, ";")
found = False
For Each c1 In cats
If c1 = c2 Then
found = True
End If
Next c1
If Not found Then
ReDim Preserve cats(0 To UBound(cats) + 1)
cats(UBound(cats)) = c2
End If
Next c2
MergeCategories = Join(cats, ";")
End Function
'--------------------------------------------------------------------
' Get a merged string of all categories for the given Conversation
' Start calling with no item, item will then be determined automatically
' and method called recursively.
'--------------------------------------------------------------------
Public Function GetCategories(conv As Conversation, Optional item As Variant = Null) As String
Dim items As SimpleItems
Dim convMail As MailItem
Dim convMeeting As MeetingItem
Dim convAppointment As AppointmentItem
Dim convPost As PostItem
If Not IsNull(item) Then
Set items = conv.GetChildren(item)
Else
Set items = conv.GetRootItems
End If
On Error Resume Next
For Each convChild In items
If TypeOf convChild Is MailItem Then
Set convMail = convChild
Debug.Print "MailItem: "; convMail.ReceivedTime; " "; convMail.Categories
GetCategories = MergeCategories(GetCategories, convMail.Categories)
ElseIf TypeOf convChild Is MeetingItem Then
Set convMeeting = convChild
Debug.Print "MeetingItem: "; convMeeting.SentOn; " "; convMeeting.Categories
GetCategories = MergeCategories(GetCategories, convMeeting.Categories)
ElseIf TypeOf convChild Is AppointmentItem Then
Set convAppointment = convChild
Debug.Print "AppointmentItem: "; convAppointment.ReplyTime; " "; convAppointment.Categories
GetCategories = MergeCategories(GetCategories, convAppointment.Categories)
ElseIf TypeOf convChild Is PostItem Then
Set convPost = convChild
Debug.Print "PostItem: "; convPost.ReceivedTime; " "; convPost.Categories
GetCategories = MergeCategories(GetCategories, convPost.Categories)
End If
GetCategories = MergeCategories(GetCategories, GetCategories(conv, convChild))
Next convChild
End Function
'--------------------------------------------------------------------
' Set a categories for all items of the given Conversation
' Start calling with no item, item will then be determined automatically
' and method called recursively.
'--------------------------------------------------------------------
Public Sub SetCategories(cats As String, conv As Conversation, Optional item As Variant = Null)
Dim items As SimpleItems
Dim convMail As MailItem
Dim convMeeting As MeetingItem
Dim convAppointment As AppointmentItem
Dim convPost As PostItem
If Not IsNull(item) Then
Set items = conv.GetChildren(item)
Else
Set items = conv.GetRootItems
End If
On Error Resume Next
For Each convChild In items
If TypeOf convChild Is MailItem Then
Set convMail = convChild
convMail.Categories = cats
convMail.Save
ElseIf TypeOf convChild Is MeetingItem Then
Set convMeeting = convChild
convMeeting.Categories = cats
convMeeting.Save
ElseIf TypeOf convChild Is AppointmentItem Then
Set convAppointment = convChild
convAppointment.Categories = cats
convAppointment.Save
ElseIf TypeOf convChild Is PostItem Then
Set convPost = convChild
convPost.Categories = cats
convPost.Save
End If
Call SetCategories(cats, conv, convChild)
Next convChild
End Sub