FAQ.APPEND_errors.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/cat
  2. $Id: FAQ.APPEND_errors.txt,v 1.13 2021/05/29 07:58:44 gilles Exp gilles $
  3. This document is also available online at
  4. https://imapsync.lamiral.info/FAQ.d/
  5. https://imapsync.lamiral.info/FAQ.d/FAQ.APPEND_errors.txt
  6. ======================================================================
  7. Dealing with Imapsync APPEND errors.
  8. ======================================================================
  9. Questions answered in this FAQ are:
  10. Q. I have an "could not append" error with
  11. "Message contains invalid header" at the end, like:
  12. Err 1/20: - msg INBOX/6 {40666} could not append ... NO Message contains invalid header
  13. What can I do to transfer these emails?
  14. Q. For some messages, the imapsync log says
  15. "could not append", sometimes followed by an explicit message
  16. describing what went wrong, or sometimes followed by a not very
  17. useful message "socket closed while reading data from server"
  18. What can I do?
  19. Q. The append error message is "NO Message contains NUL characters"
  20. What can I do?
  21. Now the questions again with their answers.
  22. ======================================================================
  23. Q. I have an "could not append" error with
  24. "Message contains invalid header" at the end, like:
  25. Err 1/20: - msg INBOX/6 {40666} could not append ... NO Message contains invalid header
  26. What can I do to transfer these emails?
  27. R0. Append in the IMAP protocol is the command to add a message in the folder.
  28. The error string "NO. Message contains invalid header" comes from the
  29. destination IMAP server at host2, it doesn't like the message and rejects it.
  30. R1. Header lines must be in 7bit encoding.
  31. If they aren't in 7bit the IMAP server can refuse them as they break
  32. the IMAP RFC specification.
  33. A solution is to transform all 8bit characters to the Z character with:
  34. imapsync ... --regexmess "tr [\x80-\xff] [Z]"
  35. Caveat: this transformation transforms both the email header and its body.
  36. It's not perfect but I guess it's better than no message transferred.
  37. So consider using it in a second pass, not the first, as 8-bit
  38. characters in the body message are allowed and changing them when
  39. not needed is not a good thing.
  40. R2. Some crappy email systems, like virus checkers or any other crappy
  41. software tool dealing with your messages, can add headers to tell
  42. the world that they've done a great job. But sometimes they didn't,
  43. and they fucked up your messages by not respecting the standard
  44. and added ugly non-rfc compliant headers.
  45. To remove an ugly header, let's call it "X-Spam-Report", that spreads over
  46. several lines beginning or, that's the ugly part, not beginning with a space:
  47. imapsync ... --regexmess 's{X-Spam-Report:.*?\n(^[a-zA-Z0-9\-]+:|^\r?\n)}{$1}xms'
  48. Thanks to Damien SAUTEREAU for reporting and solving this issue.
  49. ======================================================================
  50. Q. For some messages, the imapsync log says
  51. "could not append", sometimes followed by an explicit message
  52. describing what went wrong, or sometimes followed by a not very
  53. useful message "socket closed while reading data from server"
  54. What can I do?
  55. R0. Append errors are host2 problems, append is the imap term to copy
  56. a message to the destination account.
  57. A problem is that the assosiated "socket closed ..." error message happens
  58. for several different issues. So I list here several potential issues
  59. and their solutions if they exist.
  60. R1 deals about too long lines in messages on Windows.
  61. R2 deals about too long lines in messages on Unix.
  62. R3 deals with quota reached.
  63. R1. On Windows, add --regexmess "s,(.{9900}),$1\r\n,g"
  64. Some messages have too long lines; for example,
  65. Exchange supports only 9900 characters line length.
  66. Use this option to add "new line" characters (also called CRLF)
  67. to wrap lines longer than 9900 characters.
  68. The regex means "add one CRLF every 9900".
  69. imapsync.exe ... --regexmess "s,(.{9900}),$1\r\n,g"
  70. R2. On Unix, add --pipemess "reformime -r7". The command reformime
  71. usually belongs to the package called "maildrop".
  72. imapsync ... --pipemess "reformime -r7"
  73. I reproduce here the "reformime" manual part explaining what does
  74. the option "-r7"
  75. $ man reformime |more
  76. REFORMIME(1) Double Precision, Inc. REFORMIME(1)
  77. NAME
  78. reformime - MIME E-mail reformatting tool
  79. SYNOPSIS
  80. reformime [options...]
  81. DESCRIPTION
  82. reformime is a utility for reformatting MIME messages.
  83. Generally, reformime expects to see an RFC 2045[1] compliant message on
  84. standard input
  85. ...
  86. OPTIONS
  87. ...
  88. -r
  89. Rewrite message, adding or standardizing RFC 2045[1] MIME headers.
  90. -r7
  91. Like -r but also convert 8bit-encoded MIME sections to
  92. quoted-printable.
  93. ...
  94. Adding RFC 2045 MIME headers
  95. The -r option performs the following actions:
  96. If there is no Mime-Version:, Content-Type:, or
  97. Content-Transfer-Encoding: header, reformime adds one.
  98. If the Content-Transfer-Encoding: header contains 8bit or raw, but only
  99. seven-bit data is found, reformime changes the
  100. Content-Transfer-Encoding header to 7bit.
  101. -r7 does the same thing, but also converts 8bit-encoded content that
  102. contains eight-bit characters to quoted-printable encoding.
  103. R3. Look for the quota limit on host2. If it is the current mailbox size, don't
  104. search elsewhere. Increase the quota on the destination account.
  105. ======================================================================
  106. Q. The append error message is "NO Message contains NUL characters"
  107. What can I do?
  108. R. Use:
  109. imapsync ... --skipmess "m/(\x00)+\Z/"
  110. The option --skipmess skips messages matching a pattern, the
  111. messages are not synced, you just avoid the error messages concerning
  112. those messages.
  113. If you want to sync them, use instead:
  114. imapsync ... --regexmess "s/(\x00)+\Z//g"
  115. ======================================================================
  116. ======================================================================