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 | ´Get all registers
Dim listOfEmailConfig As List(Of EmailArchitectVO) = SDK.Query.GetEntityData(Of EmailArchitectVO)()
If Not IsNothing(listOfEmailConfig) Then
For Each emailconfigRegister As EmailArchitectVO In listOfEmailConfig
´call SDK function to get the list of inbox emails
Dim response = SDK.EmailData.HandleUnreadEmails(emailconfigRegister.emailarchitectstamp)
If Not IsNothing(response) Then
If response.messages.Count > 0 Then
´#1#´ - case of error - create a warning notice
For Each errorMessage As MessageVO In response.messages
´create a Warning notification based on errorList
Dim subject As String = "Error on get Emails"
Dim body As String = errorMessage.messageCodeLocale
Dim noticeBiz As SDKBiz = SDK.Business.CreateBiz(Notice.getEntityName)
Dim noticePhcResult As PHCResult = noticeBiz.GetNewInstance()
Dim newNotice As NoticeVO = noticePhcResult.GetResult(Of NoticeVO)()
newNotice.titlept = subject
newNotice.titlees = subject
newNotice.titleen = subject
newNotice.textpt = body
newNotice.textes = body
newNotice.texten = body
newNotice.type = NoticeType.Warning
newNotice.whoCreated = ""
noticeBiz.Save(newNotice)
Next
Else
For Each newMail As MailsData In response.result
´#2#´ - case email has Attachments - create a task & attachments
If newMail.Attachments.Length > 0 Then
´create task based on email info
Dim taskBiz As SDKBiz = SDK.Business.CreateBiz("Tasks")
Dim taskPhcResult As PHCResult = taskBiz.GetNewInstance()
Dim itemTaskVO As TasksVO = taskPhcResult.GetResult(Of TasksVO)()
itemTaskVO.summary = newMail.Subject
itemTaskVO.usstamp = ""
itemTaskVO.username = ""
itemTaskVO.startdate = SDK.Dates.timezoneDate().Date
itemTaskVO.enddate = SDK.Dates.timezoneDate().Date
itemTaskVO.description = newMail.TextBody
Dim itemTaskConnections As TaskConnectionsVO = GenericVO.GetNewInstance(Of TaskConnectionsVO)()
itemTaskConnections.tasksstamp = itemTaskVO.tasksstamp
itemTaskConnections.ParentVO = itemTaskVO
itemTaskConnections.summaryentity = LocaleManager.GetEntityName(Tasks.getTableName)
itemTaskConnections.urlextern = "/mainform/tasks/view;stamp=" + itemTaskVO.tasksstamp + ""
itemTaskVO.tc.Add(itemTaskConnections)
taskBiz.Save(itemTaskVO)
´create the attachments based on the email attachments info
For Each attach As Object In newMail.Attachments
´Get the Content (binary data) of the embedded attachment
Dim attachFile = CType(attach.Content, Byte())
´create a "attachment business object"
Dim newAttachmentBiz As SDKBiz = SDK.Business.CreateBiz("Anexos")
´Create a new attachemt instance with task reference
Dim attchemntResult As PHCResult = newAttachmentBiz.GetNewInstanceFromReference(New InstanceFromReference("Tasks", itemTaskVO.tasksstamp))
Dim itemAttachemtVO As AnexosVO = attchemntResult.GetResult(Of AnexosVO)()
itemAttachemtVO.oritable = "TASKS"
itemAttachemtVO.recstamp = itemTaskVO.tasksstamp
itemAttachemtVO.resumo = attach.Name.ToString
itemAttachemtVO.fname = attach.Name.ToString
itemAttachemtVO.fileType = attach.ContentType.ToString
´add the attachment file
itemAttachemtVO.bytefile.fileData = attachFile
itemAttachemtVO.bytefile.fileType = attach.ContentType.ToString
newAttachmentBiz.Save(itemAttachemtVO)
Next
Else
´#1#´ - case of error - create Info notification based on email info
Dim subject As String = newMail.Subject
Dim from As String = newMail.From.Address
Dim body As String = newMail.TextBody
Dim noticeBiz As SDKBiz = SDK.Business.CreateBiz(Notice.getEntityName)
Dim noticePhcResult As PHCResult = noticeBiz.GetNewInstance()
Dim newNotice As NoticeVO = noticePhcResult.GetResult(Of NoticeVO)()
newNotice.titlept = subject
newNotice.titlees = subject
newNotice.titleen = subject
newNotice.textpt = body
newNotice.textes = body
newNotice.texten = body
newNotice.type = NoticeType.Info
newNotice.whoCreated = ""
noticeBiz.Save(newNotice)
End If
Next
End If
End If
Next
End If
|