Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Commit 3840d81

Browse files
committed
Generate a UNIX From line if one was not provided.
1 parent df0c262 commit 3840d81

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

mbox/src/main/java/com/sun/mail/mbox/MboxMessage.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.io.*;
4444
import java.util.StringTokenizer;
4545
import java.util.Date;
46+
import java.text.SimpleDateFormat;
4647
import javax.activation.*;
4748
import javax.mail.*;
4849
import javax.mail.internet.*;
@@ -155,6 +156,27 @@ public synchronized InternetAddress getUnixFrom()
155156
(InternetAddress)unix_from_user.clone() : null;
156157
}
157158

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+
158180
/**
159181
* Get the date this message was received, from the UNIX From line.
160182
*
@@ -485,7 +507,7 @@ public void writeToFile(OutputStream os) throws IOException {
485507
os = new NewlineOutputStream(os, true);
486508
PrintStream pos = new PrintStream(os, false, "iso-8859-1");
487509

488-
pos.println(unix_from);
510+
pos.println(getUnixFromLine());
489511
super.writeTo(pos, null);
490512
pos.flush();
491513
} catch (MessagingException e) {

0 commit comments

Comments
 (0)