c# - Email attachment with long non-ascii name -
i try send system.net.mail.mailmessage
system.net.mail.attachment
.
name of attachment "Счёт-договор №4321 от 4 июля.pdf"
code attachment creation:
var nameencoding = encoding.utf8; return new system.net.mail.attachment(new memorystream(bytes), messagebodieshelpers.encodeattachmentname(filename, nameencoding), attachment.mediatype) { transferencoding = transferencoding.base64, nameencoding = nameencoding };
code inside messagebodieshelpers.encodeattachmentname
taken https://social.msdn.microsoft.com/forums/en-us/b6c764f7-4697-4394-b45f-128a24306d55/40-smtpclientsend-attachments-mit-umlauten-im-dateinamen?forum=dotnetframeworkde
if send attachment gmail or ms exchange, name of attachment decoded successfully. but!
if send attachment icloud "????-??????? №4321 от4 ????.pdf"
mail attachment headers:
from ms exchange:
content-type: application/pdf; name="=?utf-8?b?0khrh9gr0yit0ltq?==?utf-8?b?vtcz0l7qstc+0yag?==?utf-8?b?4oswndmymsdqvtgc?==?utf-8?b?idqg0ljrjtc70y8u?==?utf-8?b?cgrm?=" content-transfer-encoding: base64 content-disposition: attachment
from icloud:
content-transfer-encoding: base64 content-type: application/pdf; name="????-??????? =?utf-8?b?4oswndmymsdqvtgc?= 4 ????.pdf"
how format name icloud?
upd
if forward message outlook (ms exchange) icloud, name of attachment decoded successfully. headers:
content-transfer-encoding: base64 content-disposition: attachment; size=200702; modification-date="mon, 04 jul 2016 13:40:22 gmt"; filename*=utf-8''%d0%a1%d1%87%d1%91%d1%82%2d%d0%b4%d0%be%d0%b3%d0%be%d0%b2%d0%be%d1%80%20%e2%84%964321%20%d0%be%d1%82%204%20%d0%b8%d1%8e%d0%bb%d1%8f.pdf; creation-date="mon, 04 jul 2016 13:40:22 gmt" content-type: application/pdf; name*=utf-8''%d0%a1%d1%87%d1%91%d1%82%2d%d0%b4%d0%be%d0%b3%d0%be%d0%b2%d0%be%d1%80%20%e2%84%964321%20%d0%be%d1%82%204%20%d0%b8%d1%8e%d0%bb%d1%8f.pdf
upd2
if read messages using web interface of icloud (icloud.com), name of attachment decoded successfully.
in .net 4.0 smtpclient implements rfc line length limits (76 chars). required extensive changes encoding process , not covered few issues 1 describe.
in case, there issue non-ascii attachment names encoded more 41 utf-8 bytes (encoding.utf8.getbytecount(filename);). in scenario names encoded twice , may have line breaks in them. known workaround limit length of non-ascii file names.
you can read post more info issue
Comments
Post a Comment