I use javamail to handle some of the problems and solutions encountered in Chinese.

xiaoxiao2021-03-06  68

First from the most tricky. Irregular. Later, I know that it is not specified in their email .. Mail content part, such as: from: hrbtvu_ly to: foo@mail.foo.Comsubject: Hello Mime-Version: 1.0Date: Thu, 11 Nov 2004 12:51:30 0800X-MAILER: SINAMAIL 3.0Beta (Firetoad) x-priority: 3x-antivirus-mydomain-1.22-st-qms: added fake content-type headerContent-type: Text / plain

Hello, ============ e ============== Can you see that the title is Chinese, this is how to deal with it later. I The solution is to modify the getcharset (), modified: private string getcharset (string s); string s); string s1 = contenttype.getParameter "charSet"); if (S1 == null) S1 = "GB2312"; return mimeutility.javacharset (S1);} catch (exception _ex) {return "GB2312";} This is what I think the easiest way. 2. Subject or other fields are the processing of the Chinese Ming code. I provide a way I write, it is possible to unify the encoded or clear string: / ** * Return to the decoded string * / public static string getDecodeText (String EWORD) {if (eword == null) Return null; try {pattern p = pattern.compile ("= //? //? ="); matcher m = p.matcher (eword); stringbuffer sb = new Stringbuffer (); boolean result = m.find (); if (result) {while (result) {m.appendreplacement (SB, MimeUtility.DecodeExt (M.Group ())); result = m.find ();} M.Appendtail (SB); return sb.tostring ();} else {string decodevalue = new string (eword.getbytes ("ISO8859-1" ), "GBK"); return decodeValue;}}}}}}}} catch (exception e) {E.PrintStackTrace (); return eword;}} 3. Sending a message in Chinese: newmsg.setSubject (Subject, "GBK") Attachment: Base64encoder enc = new base64encoder ();

转载请注明原文地址:https://www.9cbs.com/read-87348.html

New Post(0)