|
43 | 43 | import java.io.*; |
44 | 44 | import java.util.StringTokenizer; |
45 | 45 | import java.util.Date; |
| 46 | +import java.text.SimpleDateFormat; |
46 | 47 | import javax.activation.*; |
47 | 48 | import javax.mail.*; |
48 | 49 | import javax.mail.internet.*; |
@@ -155,6 +156,27 @@ public synchronized InternetAddress getUnixFrom() |
155 | 156 | (InternetAddress)unix_from_user.clone() : null; |
156 | 157 | } |
157 | 158 |
|
| 159 | + private String getUnixFromLine() { |
| 160 | + if (unix_from != null) |
| 161 | + return unix_from; |
| 162 | + String from = "unknown"; |
| 163 | + try { |
| 164 | + Address[] froma = getFrom(); |
| 165 | + if (froma != null && froma.length > 0 && |
| 166 | + froma[0] instanceof InternetAddress) |
| 167 | + from = ((InternetAddress)froma[0]).getAddress(); |
| 168 | + } catch (MessagingException ex) { } |
| 169 | + Date d = null; |
| 170 | + try { |
| 171 | + d = getSentDate(); |
| 172 | + } catch (MessagingException ex) { } |
| 173 | + if (d == null) |
| 174 | + d = new Date(); |
| 175 | + // From shannon Mon Jun 10 12:06:52 2002 |
| 176 | + SimpleDateFormat fmt = new SimpleDateFormat("EEE LLL dd HH:mm:ss yyyy"); |
| 177 | + return "From " + from + " " + fmt.format(d); |
| 178 | + } |
| 179 | + |
158 | 180 | /** |
159 | 181 | * Get the date this message was received, from the UNIX From line. |
160 | 182 | * |
@@ -485,7 +507,7 @@ public void writeToFile(OutputStream os) throws IOException { |
485 | 507 | os = new NewlineOutputStream(os, true); |
486 | 508 | PrintStream pos = new PrintStream(os, false, "iso-8859-1"); |
487 | 509 |
|
488 | | - pos.println(unix_from); |
| 510 | + pos.println(getUnixFromLine()); |
489 | 511 | super.writeTo(pos, null); |
490 | 512 | pos.flush(); |
491 | 513 | } catch (MessagingException e) { |
|
0 commit comments