Advertisement
adamchilcott

fixImportedIMAPFolders.vbs

Aug 24th, 2018
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'This script fixes imported IMAP folders.
  2. 'It does this by modifying the value PR_CONTAINER_CLASS property;
  3. 'The value is schanged from IPF.Imap to IPF.Note.
  4.  
  5. 'Script created by: Robert Sparnaaij
  6. 'For more information about this file see;
  7. 'http://www.howto-outlook.com/howto/fix-imported-imap-folders.htm
  8.  
  9. Dim i
  10.  
  11. Call FolderSelect()
  12.  
  13. Public Sub FolderSelect()
  14.   Dim objOutlook
  15.   Set objOutlook = CreateObject("Outlook.Application")
  16.  
  17.   Dim F, Folders
  18.   Set F = objOutlook.Session.PickFolder
  19.  
  20.   If Not F Is Nothing Then
  21.     Dim Result
  22.     Result = MsgBox("Do you want to include the subfolders?", vbYesNo+vbDefaultButton2+vbApplicationModal, "Include Subfolders")
  23.  
  24.     i = 0
  25.     FixIMAPFolder(F)
  26.  
  27.     If Result = 6 Then
  28.       Set Folders = F.Folders
  29.       LoopFolders Folders
  30.     End If
  31.  
  32.     Result = MsgBox("Done!" & vbNewLine & i & " folder(s) have been fixed.", vbInfo, "Fix Imported IMAP Folders")
  33.  
  34.     Set F = Nothing
  35.     Set Folders = Nothing
  36.     Set objOutlook = Nothing
  37.   End If
  38. End Sub
  39.  
  40. Private Sub LoopFolders(Folders)
  41.   Dim F
  42.  
  43.   For Each F In Folders
  44.     FixIMAPFolder(F)
  45.     LoopFolders F.Folders
  46.   Next
  47. End Sub
  48.  
  49. Private Sub FixIMAPFolder(F)
  50.   Dim oPA, PropName, Value, FolderType
  51.  
  52.   PropName = "http://schemas.microsoft.com/mapi/proptag/0x3613001E"
  53.   Value = "IPF.Note"
  54.  
  55.   On Error Resume Next
  56.   Set oPA = F.PropertyAccessor
  57.   FolderType = oPA.GetProperty(PropName)
  58.  
  59.   'MsgBox (F.Name & " - " & FolderType)
  60.  
  61.   If FolderType = "IPF.Imap" Then
  62.     oPA.SetProperty PropName, Value
  63.     i = i + 1
  64.   End If
  65.  
  66.   Set oPA = Nothing
  67. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement