In this system, Email subjects are encoded in Q' scheme, a scheme similar to
quoted printable’. The format is “=?charset?Q?encoded subject?=”, in our case, the charset is `ISO-8859-15′.
For example, the Email object in this system is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
importjava.text.SimpleDateFormat; import java.util.Calendar; /** * Email object. * * @author Daoyuan Li */ public class Mail { /** * Sender's Email address */ private String from; /** * Recipient's Email address */ private String to; /** * Email subject */ private String subject; /** * Email message body */ private Stringmessage; /** * Constructor of Mail * @param from Sender's Email address. * @param to Recipient's Email address. * @param subject Email subject. * @param message Email message. */ public Mail(String from, String to, String subject, String message) { this.from = from; this.to = to; this.subject = subject; this.message = message; } /** * Get sender'sEmail address. * @return Sender's Email address. */ public String getFrom() { return this.from; } /** * Get Recipient's Email address. * @return Recipient's Email address. */ public String getTo() { return this.to; } /** * Get Email subject. * @return Email subject. */ public String getSubject() { return this.subject; } /** * Get Email message. * @return Email message. */ public String getMessage() { return this.message; } /** * Set sender's Email address. * @param from Sender's Email address. */ public void setFrom(String from) { this.from = from; } /** * Set Recipient's Email address. * @param to Recipient's Email address. */ public void setTo(String to) { this.to = to; } /** * Set Email subject. * @param subject Email subject. */ public void setSubject(String subject) { this.subject = subject; } /** * Set Email message. * @param message Email message. */ public void setMessage(String message) { this.message = message; } /** * Encode Email into MIMEformat. * @return The MIME encoded Email. */ public String encode() { String FORMAT = "EEE, dd MMM yyyy HH:mm:ss Z"; //String FORMAT = "yyyy-MM-dd HH:mm:ss Z"; Calendar cal = null; cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(FORMAT); //System.out.println(sdf.format(cal.getTime())); String s = "From: <" + this.getFrom() + ">\n" + "To:<" + this.getTo() + ">\n" //+ "Subject: " + this.getSubject() + "\n" + "Subject: =?ISO-8859-15?Q?" + new QuotedPrintableEncoder().encodeWithoutLineBreak(this.subject) + "?=\n" + "Date: " + sdf.format(cal.getTime()) + "\n" + "Message-ID: " + cal.getTimeInMillis() + "@ik2213.lab\n" + "MIME-Version: 1.0\n" + "Content-Type:text/plain; charset=ISO-8859-15\n" + "Content-Transfer-Encoding: quoted-printable\n"; return s.concat(new QuotedPrintableEncoder().encode(this.message)); } } |
Comments