rfc822模块中的CRLF处理

你好, 在使用RFC822模块和Imaplib时,我找到了 遵循怪异的行为. QuickStart:RFC822.Message(FP)实例 来自文件对象FP的RFC822.Message对象. RFC822的文档 模块在这里说: 从文件中读取的输入行可以通过CR-LF终止或 通过一条线馈; 终止CR-LF被单个取代 在存储行之前的线馈. 我已经通过从IMAP服务器和一个消息读取消息进行了测试 本地生成的消息; 由于我正在运行Linux,因此本地具有LF 线路终止器,而IMAP消息则使用CRLF. 以下代码段表明这两种情况会产生 结果rfc822.message对象中的不同线终结器. #V+ #!/usr/bin/python 导入Imaplib 导入RFC822 #省略任务 #imap_server = #imap_username = #imap_password = #imap_folder = def print_header(msg_str): 导入cstringio msg = rfc822.message(cstringio.stringio(msg_str)) 打印reter(msg.headers [1]) 打印reter(msg.getrawheader('envelope-to')) 打印reter(msg.getheader('envelope-to')) imap_srv = imaplib.imap4_ssl(imap_server) imap_srv.login(imap_username,imap_password) imap_srv.Select(imap_folder) 结果,响应= imap_srv.fetch(1,'(rfc822)') imap_srv.close() imap_srv.logout() print_header(响应[0] [1]) local_msg ="" \ return-Path:gathydedydeyder@gargravarr.org 信封:nikolaus@localhost 交货日期:2006年5月12日星期五05:37:22 +0200 message-id:<12 ***@bogus.org> 日期:THU,2006年5月11日20:30:44 -0700 来自:Grargravarr 到:Nikolaus Schulz 主题:Python中的伪造CRLF处理 内容类型:文本/平原; charset = us-ascii 内容转移编码:7位 虚拟邮件主体. """ print_header(local_msg) #EO:演示 #v- 运行演示脚本给出了这一点: #V+ '信封:nikolaus@localhost \ r \ n' 'Nikolaus@localhost \ r \ n' 'Nikolaus@localhost' '信封:nikolaus@localhost \ n' 'Nikolaus@localhost \ n' 'Nikolaus@localhost' #v- 那不是不一致吗? 我打了一个错误吗? 请启发我! 祝你今天过得愉快, Nikolaus

标签: python

添加新评论