SHARE
TWEET

Untitled

a guest May 22nd, 2018 240 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Sub AcceptMeeting(ActiveFolder, Inbox As String)
  2.     'Parameter: Postfach / Ordner im Postfach
  3.  
  4.     Dim myNamespace As Outlook.NameSpace
  5.     Dim myFolder As Outlook.Folder
  6.  
  7.     Dim Subfolder As Outlook.Folder
  8.     Dim Folder As Outlook.Folder
  9.     Dim Change As Outlook.Folder
  10.  
  11.     Dim Item As Object
  12.     Dim myAppt As Outlook.AppointmentItem
  13.     Dim myMtg As Outlook.MeetingItem
  14.  
  15.     'Counter to return how many Events was accepted
  16.     Dim counter As Integer
  17.     counter = 0
  18.  
  19.     Dim Forward As Outlook.MeetingItem
  20.     Dim Accept As Boolean
  21.  
  22.     Set myNamespace = Application.GetNamespace("MAPI")
  23.  
  24.     Set myFolder = myNamespace.Folders(ActiveFolder)
  25.     Set Folders = myFolder.Folders
  26.  
  27.     Set Subfolder = Folders.Item(Inbox)
  28.  
  29.     For Each Item In Subfolder.Items
  30.         DoEvents
  31.  
  32.         Accept = False
  33.  
  34.         If Item.MessageClass = "IPM.Schedule.Meeting.Request" Then
  35.  
  36.             If ActiveFolder = "Application Management Linux1, I351" Then
  37.                 Accept = True
  38.             End If
  39.  
  40.             'Label for JIRA task
  41.             Dim jiraLabel As String
  42.  
  43.             If InStr(1, LCase(Item.Subject), "change") > 0 And Item.UnRead = True And Accept = True Then
  44.                 If InStr(1, LCase(Item.Subject), "produktion") > 0 Then
  45.                     Item.Categories = "Change Produktion" 'Kategorie setzen PROD
  46.                     jiraLabel = """Produktion"""
  47.                 ElseIf InStr(1, LCase(Item.Subject), "integration") > 0 Then
  48.                     Item.Categories = "Change Integration" 'Kategorie setzen INT
  49.                     jiraLabel = """Integration"""
  50.                 ElseIf InStr(1, LCase(Item.Subject), "test") > 0 Then
  51.                     Item.Categories = "Change Integration" 'Kategorie setzen INT
  52.                     jiraLabel = """Testing"""
  53.                 Else
  54.                     Item.Categories = "Change Info" 'Kategorie setzen Info
  55.                     jiraLabel = """Info"""
  56.                 End If
  57.  
  58.                 'Accept Appointment
  59.                 Set myAppt = Item.GetAssociatedAppointment(True)
  60.                 Set myMtg = myAppt.Respond(olResponseAccepted, True)
  61.  
  62.                 Item.UnRead = False
  63.  
  64.                 If ActiveFolder = "Application Management Linux1, I351" Then
  65.  
  66.                     'Parse Email to JSON and send
  67.                     Dim Msg As Outlook.MeetingItem
  68.                     Set Msg = Item
  69.                     Set recips = Msg.Recipients
  70.                     Dim recip As Outlook.Recipient
  71.  
  72.                     Dim customBody As String
  73.                     customBody = Replace(Msg.Body, """", "'")
  74.                     customBody = Replace(customBody, vbCr & vbLf, "n")
  75.                     customBody = Replace(customBody, vbCr, "n")
  76.                     customBody = Replace(customBody, vbLf, "n")
  77.                     Dim customSubject As String
  78.                     customSubject = Replace(Msg.Subject, """", "'")
  79.                     customSubject = Replace(customSubject, vbCr & vbLf, "n")
  80.                     customSubject = Replace(customSubject, vbCr, "n")
  81.                     customSubject = Replace(customSubject, vbLf, "n")
  82.  
  83.  
  84.                     Dim regEx As New RegExp
  85.                     regEx.Pattern = "^w+sw+,sI351$"
  86.  
  87.                     For Each recip In recips
  88.                         If regEx.Test(recip.AddressEntry) And recip.AddressEntry <> "Application Management Linux1, I351" Then
  89.  
  90.  
  91.                             'Values to create JSON
  92.                             Dim flds, prt, id, asgn, smry, descrp, issu, name, lfbrkt, rtbrkt, cma, _
  93.                                 dbdots, JSON, issuName, label, startAt, endDate, sqLfBrkt, sqRtBrkt As String
  94.                             flds = """fields"""
  95.                             prt = """project"""
  96.                             id = """id"""
  97.                             asgn = """assignee"""
  98.                             smry = """summary"""
  99.                             descrp = """description"""
  100.                             issu = """issuetype"""
  101.                             label = """labels"""
  102.                             issuName = """Test"""
  103.                             startAt = """customfield_10021"""
  104.                             endDate = """customfield_12760"""
  105.                             name = """name"""
  106.                             lfbrkt = "{"
  107.                             rtbrkt = "}"
  108.                             cma = ","
  109.                             dbdots = ":"
  110.                             sqLfBrkt = "["
  111.                             sqRtBrkt = "]"
  112.  
  113.                             'Custom Date Formatting
  114.                             Dim appStartDate, appStartTime, appEndDate, appEndTime As Date
  115.                             appStartDate = myAppt.Start
  116.                             appStartTime = myAppt.Start
  117.                             appEndDate = myAppt.End
  118.                             appEndTime = myAppt.End
  119.  
  120.                             'JIRA Rest requears specific format, so we have to format out date and time
  121.                             Dim startDateString, endDateString As String
  122.                             startDateString = Format(appStartDate, "yyyy-mm-yy") + "T" + Format(appStartTime, "hh:mm") + ":00.000+0200"
  123.                             endDateString = Format(appEndDate, "yyyy-mm-dd") + "T" + Format(appEndTime, "hh:mm") + ":00.000+0200"
  124.  
  125.                             'Creating JSON - It looks scary but works
  126.                             JSON = lfbrkt + flds + dbdots + " " + lfbrkt + _
  127.                                 vbCrLf + vbTab + prt + dbdots + " " + lfbrkt + _
  128.                                     vbCrLf + vbTab + vbTab + id + dbdots + " " + "30611" + _
  129.                                 vbCrLf + vbTab + rtbrkt + cma + _
  130.                                 vbCrLf + vbTab + smry + dbdots + " " + """" + customSubject + """" + cma + _
  131.                                 vbCrLf + vbTab + descrp + dbdots + " " + """" + customBody + """" + cma + _
  132.                                 vbCrLf + vbTab + issu + dbdots + " " + lfbrkt + _
  133.                                     vbCrLf + vbTab + vbTab + name + dbdots + " " + issuName + _
  134.                                 vbCrLf + vbTab + rtbrkt + cma + _
  135.                                 vbCrLf + vbTab + asgn + dbdots + " " + lfbrkt + _
  136.                                     vbCrLf + vbTab + vbTab + name + dbdots + " " + """" + recip.AddressEntry.GetExchangeUser().Alias + """" + _
  137.                                 vbCrLf + vbTab + rtbrkt + cma + _
  138.                                 vbCrLf + vbTab + startAt + dbdots + " " + """" + startDateString + """" + cma + _
  139.                                 vbCrLf + vbTab + endDate + dbdots + " " + """" + endDateString + """" + cma + _
  140.                                 vbCrLf + vbTab + label + dbdots + " " + sqLfBrkt + jiraLabel + sqRtBrkt + _
  141.                                 vbCrLf + rtbrkt + _
  142.                                 vbCrLf + rtbrkt
  143.  
  144.                             'JIRA user
  145.                             user = "username"
  146.                             Password = "password"
  147.  
  148.                             'Sending request to JIRA
  149.                             Dim URL As String
  150.                             URL = "https://jira.app.com/rest/api/2/issue/"
  151.                             Set xhr = CreateObject("MSXML2.XMLHTTP.6.0")
  152.                             xhr.Open "POST", URL, False
  153.                             xhr.setRequestHeader "Content-Type", "application/json"
  154.                             xhr.setRequestHeader "User-Agent", "Outlook"
  155.                             xhr.setRequestHeader "Authorization", "Basic " + Base64Encode(user + ":" + Password)
  156.                             xhr.Send JSON
  157.  
  158.                         End If
  159.                     Next
  160.                     Set Change = myFolder.Folders("*** SPAM")
  161.                     Item.Move Change
  162.                 End If
  163.                 counter = counter + 1
  164.             End If
  165.         End If
  166.     Next
  167.  
  168.     MsgBox Inbox & ": " & counter & " Meetings accepted", vbOKOnly, ActiveFolder 'Infofeld
  169.  
  170. End Sub
  171.    
  172. Dim appStartDate, appStartTime, appEndDate, appEndTime As Date
  173.    
  174. Dim appStartDate as Variant
  175. Dim appStartTime as Variant
  176. Dim appEndDate as Variant
  177. Dim appEndTime as Date
  178.    
  179. Dim startDateString, endDateString As String
  180.    
  181. Dim flds, prt, id, asgn, smry, descrp, issu, name, lfbrkt, rtbrkt, cma, _
  182. dbdots, JSON, issuName, label, startAt, endDate, sqLfBrkt, sqRtBrkt As String
  183.    
  184. Dim myFolder As Outlook.Folder
  185. Set myFolder = myNamespace.Folders(ActiveFolder)
  186.  
  187. Dim Folders
  188. Set Folders = myFolder.Folders
  189.  
  190. Dim Subfolder As Outlook.Folder
  191. Set Subfolder = Folders.Item(Inbox)
  192.  
  193. Dim Folder As Outlook.Folder 'I don't see this used
  194.    
  195. For Each Item In Application.GetNamespace("MAPI").Folders(ActiveFolder).Folders.Items(Inbox).Items
  196.    
  197. Dim Forward As Outlook.MeetingItem
  198.    
  199. Dim Accept As Boolean
  200.    
  201. Sub FindMeetingRequests(ByVal targetFolder as Folder)
  202. Sub ProcessMeetingRequests(ByVal item as Object)
  203. Function BuildJSON(ByVal body as String) as String
  204. Sub SubmitJSON(ByVal JSON as String)
  205.    
  206. 'Values to create JSON
  207.                             Dim flds, prt, id, asgn, smry, descrp, issu, name, lfbrkt, rtbrkt, cma, _
  208.                                 dbdots, JSON, issuName, label, startAt, endDate, sqLfBrkt, sqRtBrkt As String
  209.                             flds = """fields"""
  210.                             prt = """project"""
  211.                             id = """id"""
  212.                             asgn = """assignee"""
  213.                             smry = """summary"""
  214.                             descrp = """description"""
  215.                             issu = """issuetype"""
  216.                             label = """labels"""
  217.                             issuName = """Test"""
  218.                             startAt = """customfield_10021"""
  219.                             endDate = """customfield_12760"""
  220.                             name = """name"""
  221.                             lfbrkt = "{"
  222.                             rtbrkt = "}"
  223.                             cma = ","
  224.                             dbdots = ":"
  225.                             sqLfBrkt = "["
  226.                             sqRtBrkt = "]"
  227. Creating JSON - It looks scary but works
  228.                             JSON = lfbrkt + flds + dbdots + " " + lfbrkt + _
  229.                                 vbCrLf + vbTab + prt + dbdots + " " + lfbrkt + _
  230.                                     vbCrLf + vbTab + vbTab + id + dbdots + " " + "30611" + _
  231.                                 vbCrLf + vbTab + rtbrkt + cma + _
  232.                                 vbCrLf + vbTab + smry + dbdots + " " + """" + customSubject + """" + cma + _
  233.                                 vbCrLf + vbTab + descrp + dbdots + " " + """" + customBody + """" + cma + _
  234.                                 vbCrLf + vbTab + issu + dbdots + " " + lfbrkt + _
  235.                                     vbCrLf + vbTab + vbTab + name + dbdots + " " + issuName + _
  236.                                 vbCrLf + vbTab + rtbrkt + cma + _
  237.                                 vbCrLf + vbTab + asgn + dbdots + " " + lfbrkt + _
  238.                                     vbCrLf + vbTab + vbTab + name + dbdots + " " + """" + recip.AddressEntry.GetExchangeUser().Alias + """" + _
  239.                                 vbCrLf + vbTab + rtbrkt + cma + _
  240.                                 vbCrLf + vbTab + startAt + dbdots + " " + """" + startDateString + """" + cma + _
  241.                                 vbCrLf + vbTab + endDate + dbdots + " " + """" + endDateString + """" + cma + _
  242.                                 vbCrLf + vbTab + label + dbdots + " " + sqLfBrkt + jiraLabel + sqRtBrkt + _
  243.                                 vbCrLf + rtbrkt + _
  244.                                 vbCrLf + rtbrkt
  245.    
  246. Const JSON_BEFORE_SUBJECT as String = lfbrkt + flds + dbdots + " " + lfbrkt + _
  247.                                 vbCrLf + vbTab + prt + dbdots + " " + lfbrkt + _
  248.                                     vbCrLf + vbTab + vbTab + id + dbdots + " " + "30611" + _
  249.                                 vbCrLf + vbTab + rtbrkt + cma + _
  250.                                 vbCrLf + vbTab + smry + dbdots + " " + """"
  251.    
  252. JSON = JSON_BEFORE_SUBJECT & customSubject & JSON_BEFORE_BODY & customBody & JSON_BEFORE_ISSUE & issuName ....
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top