惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客

博客园 - zqonline

vs2015 添加行件 获取 httponly 的 cookie 大文本编辑程序 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。 加速度传感器与车祸报警解决方案 sqlserver2008里创建系统管理员 iis+php 运行wordpress所遇到的问题 Winforms下使用TableLayoutPanel进行布局,并解决闪烁及平均列宽与平均行高问题 wince文件同步代码[转] 使用edtftpnet上传文件到Serv-U出现乱码的问题,并且不能创建中文文件名或文件夹。 升级程序到.net 4.0 发现log4net不工作与log4net conversionPattern 说明 uc密码产生方式。 SQLite数据库参数化编程时,采用命名参数的方式 System.Data.SQLite 不能在.net 4.0 里引用的解决方法 初次使用json数据格式,发生的常识性错误。 我电脑上的mssql2000居然,被黑了,在还原数据时提示:无法装载DLL Microsoft提示请误随意操作SQL数据库,以免对数据库造成不必要的麻烦或DLL所引用的某一DLL。原因:126(找不到指定模块) 解决SQL2000出现"无法执行查询,因为文件缺少或未注册。再次运行安装程序确保要求的文件已注册。"的方法 wordpress ImetaWeblog 运行时出现 “child”不是此父级的子控件。
关于 OpenSmtp 邮件标题过长后出现乱码问题的解决
zqonline · 2012-11-28 · via 博客园 - zqonline

OpenSmtp 是 .Net 平台上一个不错的邮件发送组件,但是其中存在一些 bug 影响我们的使用,我在使用中遇到了邮件主题长度较大时,邮件出现乱码的情况。

    经过检查源代码发现,原来的处理过程存在问题:首先主题是通过 ASCII 编码的,其次,使用了 QP 编码,但没有考虑主题与内容的区别。

    在主题中编码时,每一行必须都要单独编码,不可将主题全部编码。

    经过与 Outlook Express 对比,在 MailEncoding 类中增加一个方法,专门针对邮件主题进行 Base64 编码

public static string ConvertHeaderToBase64(string s, string charset)
  {
   int lineLength = 40;           // 每行处理 40 个字节
   Encoding encoding = Encoding.GetEncoding( charset );   // 取指定编码
   byte[] buffer = encoding.GetBytes( s );       // 转换为字节码

   StringBuilder sb = new StringBuilder();       // 保存最终结果
   string linebase64 ;            

   int block = buffer.Length%lineLength==0?buffer.Length/lineLength:buffer.Length/lineLength + 1;

   for(int i=0; i< block; i++)
   {
    if( buffer.Length - i*lineLength >=lineLength )
     linebase64 = Convert.ToBase64String( buffer, i*lineLength, lineLength );
    else
     linebase64 = Convert.ToBase64String( buffer, i*lineLength, buffer.Length - i*lineLength);
    sb.Append( "=?" );
    sb.Append( charset );
    sb.Append( "?B?" );
    sb.Append( linebase64 );
    sb.Append( "?=\r\n\t" );
   }
   sb.Remove( sb.Length-3, 3);          // 删除最后的换行符号
   return  sb.ToString();
  }

    然后,将 MailMessage 类中的 ToString 方法中对邮件主题的处理修改为调用自定义的方法

                

//    sb.Append("Subject: " + MailEncoder.ConvertHeaderToQP(cleanSubject.ToString(), charset) + "\r\n");
    sb.Append("Subject: " + MailEncoder.ConvertHeaderToBase64( cleanSubject.ToString(), charset) + "\r\n");

   重新编译即可