Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub extractFolders(strMailboxName, intFullName, objNameSpace)
  2.     'On Error Resume Next
  3.    
  4.     Dim objFolder
  5.     Dim objMsg
  6.     Dim strAttachments
  7.     Dim Atmt
  8.     Dim strSenderEmailAddress
  9.     Dim strRecipientEmails
  10.     Dim RecptEmail
  11.     Dim objEmails
  12.     Dim intItemCount
  13.  
  14.     For Each objFolder In objNameSpace.Folders
  15.        
  16.         DoEvents
  17.    
  18.         If objFolder.Name = strMailboxName Or (InStr(intFullName & "\" & objFolder.Name, "\" & strMailboxName & "\") > 0 And _
  19.             objFolder.Name <> "RSS Feeds" And _
  20.             objFolder.Name <> "Junk E-mail" And _
  21.             objFolder.Name <> "News Feed" And _
  22.             objFolder.Name <> "Sync Issues" And _
  23.             objFolder.Name <> "Tasks" And _
  24.             objFolder.Name <> "Suggested Contacts" And _
  25.             objFolder.Name <> "Sent Items" And _
  26.             objFolder.Name <> "Quick Step Settings" And _
  27.             objFolder.Name <> "Outbox" And _
  28.             objFolder.Name <> "Junk E-Mail" And _
  29.             objFolder.Name <> "Journal" And _
  30.             objFolder.Name <> "Drafts" And _
  31.             objFolder.Name <> "Deleted Items" And _
  32.             objFolder.Name <> "Conversation Action Settings" And _
  33.             objFolder.Name <> "Contacts" And _
  34.             objFolder.Name <> "Calendar" And _
  35.             objFolder.Name <> "Insulator" And _
  36.             objFolder.Name <> "Notes") Then
  37.  
  38.             Set objEmails = objFolder.Items
  39.  
  40.             objEmails.Sort "[ReceivedTime]", True
  41.  
  42.             Set objEmails = objEmails.Restrict("[ReceivedTime] > '" & DateAdd("d", -1, DateAdd("m", -6, Date)) & "'")
  43.  
  44.             intItemCount = objEmails.count
  45.  
  46.             Do While intItemCount > 0
  47.                
  48.                 DoEvents
  49.                
  50.                 If TypeName(objEmails(intItemCount)) = "MailItem" Then
  51.  
  52.                     Set objMsg = objEmails(intItemCount)
  53.  
  54.                     With objMsg
  55.                         strAttachments = ""
  56.  
  57.                         For Each Atmt In .Attachments
  58.                             If Atmt <> "Picture (Device Independent Bitmap)" Then
  59.                                 If Left(Atmt.FileName, 5) <> "image" And Right(Atmt.FileName, 3) <> "png" Then
  60.                                     If strAttachments <> "" Then strAttachments = strAttachments & "; "
  61.  
  62.                                     strAttachments = strAttachments & Atmt.FileName
  63.                                 End If
  64.                             End If
  65.                         Next
  66.  
  67.                         strSenderEmailAddress = .SenderEmailAddress
  68.                         If InStr(strSenderEmailAddress, "/") > 0 Then
  69.                             'strSenderEmailAddress = .Sender.GetExchangeUser.PrimarySmtpAddress
  70.                        End If
  71.  
  72.                         strRecipientEmails = ""
  73.  
  74.                         For Each RecptEmail In .Recipients
  75.                             If strRecipientEmails <> "" Then strRecipientEmails = strRecipientEmails & "; "
  76.  
  77.                             'If InStr(RecptEmail.Address, "/") > 0 Then
  78.                            '    Err.Clear
  79.  
  80.                             '    strRecipientEmails = strRecipientEmails & RecptEmail.AddressEntry.GetExchangeUser.PrimarySmtpAddress
  81.  
  82.                             '    If Err.Number <> 0 Then
  83.                            '        strRecipientEmails = strRecipientEmails & "Unresolved Recipient Address"
  84.                            '        Err.Clear
  85.                            '    End If
  86.                            'Else
  87.                                strRecipientEmails = strRecipientEmails & RecptEmail '.AddressEntry.Address
  88.                            'End If
  89.                        Next
  90.  
  91.                         saveEmailData .EntryID, .Subject, .SenderName, strSenderEmailAddress, .To, strRecipientEmails, strAttachments, .CC, .flagStatus, .TaskCompletedDate, .Categories, .ReceivedTime, intFullName & "\" & objFolder.Name, strMailboxName, .Body
  92.                     End With
  93.                 End If
  94.  
  95.                 intItemCount = intItemCount - 1
  96.             Loop
  97.  
  98.             If objFolder.Folders.count > 0 Then
  99.                 extractFolders strMailboxName, intFullName & "\" & objFolder.Name, objFolder
  100.             End If
  101.         End If
  102.     Next
  103. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement