The Pixel Wall

The Blog Of Dan

Moving IMAP email to Exchange

While moving email from Open Source version of Zimbra (Which only supports IMAP in Outlook, as it has its own Zimbra Client) to a Microsoft Exchange based system I ran into a strange problem. In Outlook E-Mails in folders would not show, yet they would on the OWA (Webmail) interface.

This is because when the folders got exported they had retained the views associated with the IMAP account. The default IMAP view is to “Hide messages marked for deletion”. Microsoft Exchange doesn’t support marking messages, so the view in Outlook hides all messages in those folders. The folders will also say “Filter Applied”.

This can be fixed by running a Macro which will pass through each folder and sub-folder and change the value from an IMAP type to Note type. The Note type is the default Outlook style folder.

Macro with Thanks to –

Option Explicit
Dim SubFolder As MAPIFolder
Sub ChangeFolderClassAllSubFolders()
    Dim i               As Long
    Dim iNameSpace      As NameSpace
    Dim myOlApp         As Outlook.Application
    Dim ChosenFolder    As Object
    Dim Folders         As New Collection
    Dim EntryID         As New Collection
    Dim StoreID         As New Collection
    Set myOlApp = Outlook.Application
    Set iNameSpace = myOlApp.GetNamespace("MAPI")
    Set ChosenFolder = iNameSpace.PickFolder
    If ChosenFolder Is Nothing Then
GoTo ExitSub:
    End If
    Call GetFolder(Folders, EntryID, StoreID, ChosenFolder)
    For i = 1 To Folders.Count
        Set SubFolder = myOlApp.Session.GetFolderFromID(EntryID(i), StoreID(i))
        On Error Resume Next
        On Error GoTo 0
    Next i    
End Sub
Private Sub ChangeFolderContainer()
Dim oFolder As Outlook.folder
Dim oPA As Outlook.PropertyAccessor
Dim PropName, Value, folderType As String
Value = "IPF.Note"
On Error Resume Next
Set oFolder = SubFolder 'Application.ActiveExplorer.CurrentFolder
Set oPA = oFolder.PropertyAccessor
folderType = oPA.GetProperty(PropName)
Debug.Print SubFolder.Name & " " & (folderType)
If folderType = "IPF.Imap" Then
oPA.SetProperty PropName, Value
Debug.Print "     Changed: " & SubFolder.Name & " " & Value
End If
Set oFolder = Nothing
Set oPA = Nothing
End Sub
Sub GetFolder(Folders As Collection, EntryID As Collection, StoreID As Collection, Fld As MAPIFolder)
    Dim SubFolder       As MAPIFolder
    Folders.Add Fld.FolderPath
    EntryID.Add Fld.EntryID
    StoreID.Add Fld.StoreID
    For Each SubFolder In Fld.Folders
        GetFolder Folders, EntryID, StoreID, SubFolder
    Next SubFolder
    Set SubFolder = Nothing
End Sub

, , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *