Invalid rfc5322 message: failed to parse Sender header

Hi there,

I’m using eM Client to migrate tens of thousands of e-mails from Gmail to Proton Mail.

Since Proton Mail is fully encrypted it has this Proton Mail Bridge installed locally on my Mac that will expose regular IMAP and SMTP for eM Client.

I have added both my Gmail account and Proton Mail account to eM Client and then move folder-by-folder. (Moving or copying all e-mails just crashes eM Client).

I get a bunch of different errors, this is one of them:

[IMAP] BAD invalid rfc5322 message: failed to parse Sender header: [Error offset=61]: expected ':' for group start

I can use Edit item to open the e-mail. But there isn’t anything wrong with it and I cannot delete it to prevent it from causing problems. I can also click “Ignore” but I’m not sure what that actually does. I’m pretty sure it just gets queued and will fail again later.

It’s possible this error comes directly from Proton Mail or the Bridge client, but eM Client doesn’t really make it easy to know where the error comes from or how to progress in the troubleshooting.

Other errors are:
[IMAP] NO failed to retrieve addresses from literal:failed to parse addresses for 'To': [Error offset=81]: expected byte value 3f: known recovered message, possible duplication

and

[IMAP] BAD invalid rfc5322 message: failed to parse From header: [Error offset=178]: expected ':' for group start

and

[IMAP] NO failed to import message: failed to import message: Imported message is not fully encrypted (Code=36027, Status=0): known recovered message, possible duplication

Does that mean you won’t delete it, or if you try to delete it, it fails?

It means it opens this window. And it doesn’t have any “Delete” button that I could find.

And I’m not sure what this window contains. Is it a message on the Gmail servers? Is it in some buffer in eM Client waiting to be uploaded? I’m not sure how to find “it” and from where I should delete it from to avoid the problem. Ofc better than deleting would have the messages not fail in the first place (:

If you need to keep the message, first right-click in the message body and choose Save As. That will create an eml file on your device.

Then click on Menu > Message > Delete.

Thanks! I’m fairly new to MacOS and totally forgot there’s this menu bar not in the actual application window but stuck all the way up top :man_facepalming:

That being said I deleted one of the messages. It didn’t seem to disappear from the Error log so I clicked “Ignore” to remove it. Then moved on to Edit item on the next one when eM Client crashed.

I’ve managed to clean up most now with a couple of crashes.

Now another frequent problem arises with a huge stack trace but without enough information to be useful:

23:11:52 [email protected] IMAP Synchronizing folder list
23:11:53 [email protected] IMAP Uploading item(s) to folder '/Folders/_Startups/_Strandheimveien'
23:11:53 [email protected] [IMAP] MailClient.Accounts.ConnectionException: Uploading item(s) to folder '[email protected]/Folders/_Startups/_Strandheimveien' failed due to the following error: Connection was closed
          ---> MailClient.Imap.Base.ByeException: Connection was closed
          ---> System.Threading.Tasks.TaskCanceledException: TaskCanceledException_ctor_DefaultMessage
            at MailClient.Imap.Base.LiteralCompletion.AwaitAndResetAsync(CancellationToken cancellationToken)
            at MailClient.Imap.Base.LiteralParameter.OutputAsync(PipeWriter writer, ILiteralCompletion literalCompletion, CancellationToken cancellationToken)
            at MailClient.Imap.Base.Connection.RunCommandAsync(Command command, Func`3 notificationCallback)
            Exception_EndOfInnerExceptionStack
            at MailClient.Imap.Base.Connection.RunCommandAsync(Command command, Func`3 notificationCallback)
            at MailClient.Protocols.Imap.ImapMailSynchronizer.<>c__DisplayClass94_0.<<AppendAsync>g__DoAppendAsync|1>d.MoveNext()
         --- End of stack trace from previous location ---
            at MailClient.Protocols.Imap.ImapMailSynchronizer.AppendAsync(IItemUploadContext`1 uploadContext, FolderInfo info, UploadItem item, CancellationToken cancellationToken)
            at MailClient.Protocols.Imap.ImapMailSynchronizer.AppendAsync(IItemUploadContext`1 uploadContext, FolderInfo info, UploadItem item, CancellationToken cancellationToken)
            at MailClient.Protocols.Imap.ImapMailSynchronizer.UploadAsync(IItemUploadContext`1 uploadContext, Folder folder, IEnumerable`1 items, CancellationToken cancellationToken)
            at MailClient.Protocols.Imap.ImapMailSynchronizer.Upload(IItemUploadContext`1 uploadContext, Folder folder, IEnumerable`1 items, CancellationToken cancellationToken)
            at MailClient.Protocols.Common.ItemSynchronizer`2.<>c__DisplayClass35_0.<EnqueueUpload>b__0(WorkerStatus status, CancellationToken cancellationToken)
            at MailClient.Protocols.Imap.ImapActionCommand.<>c__DisplayClass11_0.<.ctor>b__0(WorkerStatus ws, CancellationToken ct)
            at MailClient.Protocols.Imap.ImapActionCommand.ExecuteInternalSync(WorkerStatus status)
            Exception_EndOfInnerExceptionStack
            at MailClient.Protocols.Imap.ImapActionCommand.ExecuteInternalSync(WorkerStatus status)
            at MailClient.Protocols.Imap.ImapActionCommand.Execute(WorkerStatus status)
            at MailClient.Commands.Command.Process(WorkerStatus status)
           IMAP_SERVER_TYPE = ProtonMail
           EnqueuedStackTrace =
                at MailClient.Protocols.Common.ItemSynchronizer`2.EnqueueUpload(Folder folder, IEnumerable`1 items, Action`1 completed)
                at MailClient.Protocols.Common.ItemSynchronizer`2.GoOnline()
                at MailClient.Protocols.Imap.ImapMailSynchronizer.GoOnline()
                at MailClient.Protocols.Imap.ImapAccount.GoOnlineInt()
                at MailClient.Protocols.Common.AccountBase.ChangeOnlineState(Boolean online, OfflineReason offlineReason)
                at MailClient.Protocols.Common.AccountBase.GoOnline()
                at MailClient.Protocols.Common.AccountBase.RunIfOnline[T](Func`1 actionIfOnline, Func`1 actionIfOffline)
                at MailClient.Protocols.Common.SynchronizableMailAccount.Synchronize(SynchronizationPriority priority)
                at MailClient.Accounts.BindingAccountBase.Receive()
                at MailClient.UI.Controls.Folders.controlFolders.treeView_NodeClicked(Object sender, TreeViewCancelEventArgs e)
                at MailClient.Common.UI.Controls.ControlTreeView.ControlTreeView.OnNodeClicked(TreeViewCancelEventArgs e)
                at MailClient.Common.UI.Controls.ControlTreeView.ControlTreeView.OnMouseDown(MouseEventArgs e)
                at System.Windows.Forms.Control.WmLButtonDown(Message& m)
                at System.Windows.Forms.Control.WndProc(Message& m)
                at MailClient.Common.UI.Controls.NonFlickeringUserControl.WndProc(Message& m)
                at MailClient.Common.UI.Controls.AutomationViewUserControl.WndProc(Message& m)
                at MailClient.Common.UI.Controls.TouchScrollUserControl.WndProc(Message& m)
                at System.Windows.Forms.NativeWindow.WndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam)
                at System.Windows.Forms.Application.SendMessage(MSG& msg, Boolean& drop, Boolean& quit)
                at System.Windows.Forms.Application.SendMessage(MSG& msg)
                at System.Windows.Forms.CocoaInternal.WindowsEventResponder.TranslateMouseDown(NSEvent e)
                at System.Windows.Forms.CocoaInternal.WindowsEventResponder.MouseDown(NSEvent theEvent)
                at System.Windows.Forms.CocoaInternal.MonoView.MouseDown(NSEvent theEvent)
                at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
                at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
                at ObjCRuntime.Runtime.InvokeMethod(MethodBase method, Object instance, IntPtr native_parameters)
                at ObjCRuntime.Runtime.InvokeMethod(MonoObject* methodobj, MonoObject* instanceobj, IntPtr native_parameters)
                at ObjCRuntime.Runtime.bridge_runtime_invoke_method(MonoObject* method, MonoObject* instance, IntPtr parameters, IntPtr& exception_gchandle)
                at ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle(IntPtr receiver, IntPtr selector, NativeHandle arg1)
                at ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle(IntPtr receiver, IntPtr selector, NativeHandle arg1)
                at AppKit.NSWindow.SendEvent(NSEvent theEvent)
                at System.Windows.Forms.CocoaInternal.MonoWindow.SendEvent(NSEvent theEvent)
                at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
                at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
                at ObjCRuntime.Runtime.InvokeMethod(MethodBase method, Object instance, IntPtr native_parameters)
                at ObjCRuntime.Runtime.InvokeMethod(MonoObject* methodobj, MonoObject* instanceobj, IntPtr native_parameters)
                at ObjCRuntime.Runtime.bridge_runtime_invoke_method(MonoObject* method, MonoObject* instance, IntPtr parameters, IntPtr& exception_gchandle)
                at ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle(IntPtr receiver, IntPtr selector, NativeHandle arg1)
                at ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle(IntPtr receiver, IntPtr selector, NativeHandle arg1)
                at AppKit.NSApplication.SendEvent(NSEvent theEvent)
                at System.Windows.Forms.XplatUICocoa.PumpNativeEvent(Boolean wait, MSG& msg, Boolean dequeue)
                at System.Windows.Forms.XplatUICocoa.GetMessage(Object queue_id, MSG& msg, IntPtr hWnd, Int32 wFilterMin, Int32 wFilterMax)
                at System.Windows.Forms.Application.RunLoop(Boolean Modal, ApplicationContext context)
                at System.Windows.Forms.Application.Run(ApplicationContext context)
                at MailClient.Program.Main(String[] args)
           GUIStatus_Exception_Reported = True
23:11:53 [email protected] [IMAP] System.Threading.Tasks.TaskCanceledException: TaskCanceledException_ctor_DefaultMessage
            at MailClient.Protocols.Imap.ImapAccount.SynchronizeIntAsync(Boolean forced)
            at MailClient.Protocols.Common.SynchronizableMailAccount.<>c__DisplayClass7_0.<<SynchronizeAsync>b__0>d.MoveNext()
           GUIStatus_Exception_Reported = True
23:12:59 [email protected] IMAP Synchronizing folder list

This is probably not eM Client’s fault. I’m guessing there is some malformed message in that folder that makes Proton Bridge crap itself and close the connection (unless eM Client is masking some other error).

Previously I’ve solved this by splitting the messages in a folder into 10 subfolders and them moving each one until one of them fails. Splitting that again into 10 subfolders and so on until I find the faulty message. Needless to say it’s quite time consuming though. Especially in folders where there are multiple faulty messages.