andrewtimberlake/mailroom

Mailroom.IMAP.fetch(client, msg_id, "BODY.PEEK[]") returns two maps

Closed this issue · 6 comments

When I process an email, sometimes Mailroom.IMAP.fetch(client, msg_id, "BODY.PEEK[]") returns something like (note the second map)

[
  {1, %{"BODY[]" => "Return-Path: ...}},
  {1, %{flags: ["\\Recent", "$NotJunk", "NotJunk"]}}
]

which crashes Inbox.fetch_mail since [{^msg_id, %{"BODY[]" => mail}}] does not match. Changing the pattern matching to

{:ok, [{^msg_id, %{"BODY[]" => mail}} | _rest]} = Mailroom.IMAP.fetch(client, msg_id, "BODY.PEEK[]")

fixes the exception but I wonder why Mailroom.IMAP.fetch(client, msg_id, "BODY.PEEK[]") does return the flags as well, not only the BODY[] map? I'm far from an IMAP expert, though.

Hi @gernotkogler, Which IMAP server are you connecting to? (software or service, not account)
You say “sometimes”, is it possible to reproduce the conditions that causes the double return?

Hi @andrewtimberlake

The mail server I'm connecting to is mail.cyon.ch. Don't know what software they're running, but I can ask if that helps.
It took me quite a while to reliably reproduce the error.

It occurs when I send the mail as gernot@kogler-informatik.ch (my own o365 account). It does NOT happen when I send the test Email with my company account gernot.kogler@garaio-rem.ch (also a o365 account)

Does that help?

@gernotkogler Please enable debug in the mailroom config:

config :myapp, :mailroom,
  server: "imap....",
  #...
  debug: true

and then process a single failing email.
That will produce a lot off `> [ssl]' and '< [ssl]' prefixed information
Go through it and redact anything confidential and email it to me at andrew@andrewtimberlake.com and I’ll figure out what’s going on.

Thanks for the info. I have pushed a fix to master. Please see if that fixes the problem.

Thanks, I’ve released 0.5.1