Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET IMAP

 AfterLogic Forum : MailBee.NET IMAP
Subject Topic: Having Issues with Message Flags Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
ramiss
Newbie
Newbie
Avatar

Joined: 18 March 2009
Location: United States
Online Status: Offline
Posts: 5
Posted: 18 March 2009 at 1:21am | IP Logged Quote ramiss

I have been using this component for several hours and I love it.

Here is the issue...I have written an IMAP migration function. It works great except that I cannot seem to retain the Un-Read flag.

As you can see we are using .ExamineFolder along with .DownloadEnvelopes and both the Source and Target messages are all set to Read after this is run.

I would be ok with going back and setting the flags back afterwards except I am not sure how.

Thanks for any help!

Richard

*********

Code:

Public Function MigrateIMAP(ByVal HostAddress_Source As String, ByVal HostPort_Source As String, ByVal HostSSL_Source As String, ByVal HostAddress_Target As String, ByVal HostPort_Target As String, ByVal HostSSL_Target As String, ByVal UserEmail_Source As String, ByVal UserPass_Source As String, ByVal UserEmail_Target As String, ByVal UserPass_Target As String) As Array
        Dim ReturnArr(2)
        Try
             Application.DoEvents()
             Dim impSource As New Imap
             Dim impTarget As New Imap
             Dim SourceRange As String
             Dim SourceEnvelopes As EnvelopeCollection
             Dim TargetRange As String
             Dim TargetEnvelopes As EnvelopeCollection
             Dim SourceFolders As FolderCollection
             'Dim TargetFolders As FolderCollection
             Dim CurrentFolderPath As String = ""
             Dim msg1 As MailBee.Mime.MailMessage
             Dim FoundExistingMsg As Boolean

             ' Connect to the Source Server and login and select inbox.
             If HostSSL_Source Then
                 impSource.SslMode = Security.SslStartupMode.OnConnect
             End If
             impSource.Connect(HostAddress_Source,  HostPort_Source)
             impSource.Login(UserEmail_Source,  UserPass_Source)

             ' Connect to the Target Server and login and select inbox.
             If HostSSL_Target Then
                 impTarget.SslMode = Security.SslStartupMode.OnConnect
             End If
             impTarget.Connect(HostAddress_Target,  HostPort_Target)
             impTarget.Login(UserEmail_Target,  UserPass_Target)

             ' Loop Through Source Folders
             SourceFolders = impSource.DownloadFolders()
             For Each FolderPath As Folder In SourceFolders
                 Application.DoEvents()
                 'WriteStr(CurrentFolderPath, False)
                 CurrentFolderPath = FolderPath.RawName

                 'Set the Source Folder - Use ExamineFolder for ReadOnly and to keep flags
                 'impSource.SelectFolder(CurrentFolderPath)
                 impSource.ExamineFolder(CurrentFolderPath)

                 'Create Folder on Target Server
                 Try
                     impTarget.CreateFolder(CurrentFolderPath)
                 Catch
                 End Try
                 'Set the Target Folder
                 impTarget.ExamineFolder(CurrentFolderPath)

                 'Get all Source Messages
                 SourceRange = Imap.AllMessages

                 ' Get envelopes for the specified messages.
                 SourceEnvelopes = impSource.DownloadEnvelopes(SourceRange, False)

                 For Each env As Envelope In SourceEnvelopes
                      Application.DoEvents()
                      'WriteStr(env.MessageID, False)
                      'Check all emails on the Target Server for identical Messages
                      'Get all Target Messages
                     TargetRange = Imap.AllMessages
                     TargetEnvelopes = impTarget.DownloadEnvelopes(TargetRange, False)

                      'Loop through each msg on Target Server
                     FoundExistingMsg = False
                     For Each envTarget As Envelope In TargetEnvelopes
                          If envTarget.MessageID = env.MessageID Then FoundExistingMsg = True
                     Next

                      If Not FoundExistingMsg Then
                           Try
                               'WriteStr("Flags: " & env.Flags.ToString, False)
                               msg1 = impSource.DownloadEntireMessage(env.Uid, True)
                               msg1.ThrowExceptions = False
                               impTarget.UploadMessage(msg1, CurrentFolderPath, env.Flags.ToString, msg1.[Date])
                           Catch e As MailBeeException
                               WriteStr("Error Migrating IMAP Msg: " & e.Message, False)
                           End Try
                     End If
                 Next

             Next
             ' Disconnect from the server.
             impSource.Disconnect()
             impTarget.Disconnect()
             ReturnArr = Split("true,,,", ",")
        Catch ex As Exception
             WriteStr("Error MigrateIMAP Function: " & ex.Message, False)
             ReturnArr = Split("false,," & ex.Message & ",", ",")
        End Try
        MigrateIMAP = ReturnArr
    End Function
Back to Top View ramiss's Profile Search for other posts by ramiss
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 18 March 2009 at 2:33am | IP Logged Quote Andrew

If I understood you correctly, ExamineFolder doesn't prevent setting SEEN flag in your case. Some IMAP servers ignore attempt to open mailbox in read-only mode and mark messages as seen on downloading anyway.

To prevent this, please try downloading messages via this overload of Imap.DownloadEnvelopes method. The key is to use parts = EnvelopeParts.MessagePreview and bodyPreviewSize = -1. This will download entire messages within envelopes and should prevent setting SEEN flag.

Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide