{"action":"created","issue":{"url":"https://api.github.com/repos/neomutt/neomutt/issues/722","repository_url":"https://api.github.com/repos/neomutt/neomutt","labels_url":"https://api.github.com/repos/neomutt/neomutt/issues/722/labels{/name}","comments_url":"https://api.github.com/repos/neomutt/neomutt/issues/722/comments","events_url":"https://api.github.com/repos/neomutt/neomutt/issues/722/events","html_url":"https://github.com/neomutt/neomutt/issues/722","id":251423216,"number":722,"title":"(neo)mutt converts CRLF to LF in attachments with mime text/*","user":{"login":"carlytinnerello","id":31159660,"avatar_url":"https://avatars1.githubusercontent.com/u/31159660?v=4","gravatar_id":"","url":"https://api.github.com/users/carlytinnerello","html_url":"https://github.com/carlytinnerello","followers_url":"https://api.github.com/users/carlytinnerello/followers","following_url":"https://api.github.com/users/carlytinnerello/following{/other_user}","gists_url":"https://api.github.com/users/carlytinnerello/gists{/gist_id}","starred_url":"https://api.github.com/users/carlytinnerello/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlytinnerello/subscriptions","organizations_url":"https://api.github.com/users/carlytinnerello/orgs","repos_url":"https://api.github.com/users/carlytinnerello/repos","events_url":"https://api.github.com/users/carlytinnerello/events{/privacy}","received_events_url":"https://api.github.com/users/carlytinnerello/received_events","type":"User","site_admin":false},"labels":[{"id":302065905,"url":"https://api.github.com/repos/neomutt/neomutt/labels/status:new-bug","name":"status:new-bug","color":"1d76db","default":false},{"id":523548908,"url":"https://api.github.com/repos/neomutt/neomutt/labels/type:bug","name":"type:bug","color":"ff0000","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-08-19T12:51:00Z","updated_at":"2017-08-20T06:06:54Z","closed_at":null,"body":"Hi\r\n\r\nWhen mutt saves/pipes an attachment which has MIME type text/* it converts any CRLF into LF (at least on Linux).\r\nThis, however, renders some attachments useless.\r\n\r\n* It changes the checksum of files which contain a CRLF (example mail attached below) thus disturbing cryptographic verifications (Here I do not mean S/MIME, PGP/MIME).\r\n* It damages files which are (willingly or accidentally) marked as text/*. For example Thunderbird sends (at least under some circumstances) PDF documents as text/pdf. Which then cannot be read by any PDF viewer any more.\r\n\r\nIn the spirit of the Robustness Principle 'be conservative in what you do, be liberal in what you accept from others', I suggest adding a command <save-raw-entry>/<save-entry-as-binary> (name is up for discussion) which saves the attachment/part of the mail without modifying it, only stripping the transfer encoding.\r\n\r\nLooking into the code base, the function which tampers with the line endings is mutt_decode_base64 in handler.c. If the istext parameter is true, then it converts CRLF to LF.\r\nThe function itself is called by mutt_decode_attachment which sets istext to true if the attachment has MIME type text/*, message/*, application-gpg/pgp-keys.\r\nThe function mutt_decode_attachment is used by mutt_pipe_attachment and mutt_save_attachment in attach.c and by pipe_attachment in recvattach.c (but there might also be others).\r\nOther encodings (e.g. quoted printable) seem not to have this issue.\r\n\r\nTemporary workaround for people which have this problem:\r\na) Save the mail (as a whole) to a temporary mailfolder (maildir or mbox). Then edit the file such that the ContentType of the attachment is application/pdf, application/octet-stream, ...\r\nNow open the mailfolder and save the attachment.\r\nb) Alternatively, save the mail to a file extract the base64 encoded stuff and decode it yourself (e.g. with 'base64 -d').\r\n\r\nBest\r\ncarly\r\n\r\nHere is an example message to reproduce the problem\r\n```\r\nFrom: test@example.org\r\nTo: test@example.com\r\nSubject: Test text attachment\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"XsQoSWH+UP9D9v3l\"\r\nContent-Disposition: inline\r\nX-Mutt-Fcc: =sent\r\nDate: Sat, 19 Aug 2017 12:27:10 +0000\r\n\r\n\r\n--XsQoSWH+UP9D9v3l\r\nContent-Type: text/plain; charset=us-ascii\r\nContent-Disposition: inline\r\n\r\nThe MD5 sum of the attachment send (which contained a CRLF) was\r\n\r\n    12b81ead7c0b006dea3a7195934fb921\r\n\r\nThe attachment saved has\r\n\r\n    ef05821d23a256a0f0e0b330348819d4\r\n\r\n--XsQoSWH+UP9D9v3l\r\nContent-Type: text/plain; charset=us-ascii\r\nContent-Disposition: attachment; filename=\"test.txt.crlf\"\r\nContent-Transfer-Encoding: base64\r\n\r\naGVyZSBpcyBhIENSTEYNCm5leHQgbGluZQo=\r\n\r\n--XsQoSWH+UP9D9v3l--\r\n```"},"comment":{"url":"https://api.github.com/repos/neomutt/neomutt/issues/comments/323565968","html_url":"https://github.com/neomutt/neomutt/issues/722#issuecomment-323565968","issue_url":"https://api.github.com/repos/neomutt/neomutt/issues/722","id":323565968,"user":{"login":"carlytinnerello","id":31159660,"avatar_url":"https://avatars1.githubusercontent.com/u/31159660?v=4","gravatar_id":"","url":"https://api.github.com/users/carlytinnerello","html_url":"https://github.com/carlytinnerello","followers_url":"https://api.github.com/users/carlytinnerello/followers","following_url":"https://api.github.com/users/carlytinnerello/following{/other_user}","gists_url":"https://api.github.com/users/carlytinnerello/gists{/gist_id}","starred_url":"https://api.github.com/users/carlytinnerello/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlytinnerello/subscriptions","organizations_url":"https://api.github.com/users/carlytinnerello/orgs","repos_url":"https://api.github.com/users/carlytinnerello/repos","events_url":"https://api.github.com/users/carlytinnerello/events{/privacy}","received_events_url":"https://api.github.com/users/carlytinnerello/received_events","type":"User","site_admin":false},"created_at":"2017-08-20T06:06:54Z","updated_at":"2017-08-20T06:06:54Z","body":"> Does the pipe_decode setting affect this at all?\r\n\r\nI don't think so.\r\n\r\nFollowing the option OPT_PIPE_DECODE, it is only used in mutt_pipe_message() and _mutt_pipe_message() in the file command.c, which I doubt are called when saving attachments (calling sites are mutt_index_menu() in curs_main.c and mutt_pager() in pager.c). From there pipe_msg() is called which invokes mutt_parse_mime_message() in parse.c. From a quick look I don't think that mutt_parse_mime_message() (and its follow ups) does strip the content-transfer-encoding."}}
{"actor":{"display_login":"carlytinnerello"}}