Skip to content
Permalink
Browse files
[EXAMPLES] MessageTree should be easy to launch from an IDE
We can default to a local resource if no argument is provided.
  • Loading branch information
chibenwa committed Jun 29, 2021
1 parent 8591c45 commit 6d2e66423fa50fec84b4684ed94819ffd18bab31
Showing 2 changed files with 55 additions and 4 deletions.
@@ -362,9 +362,10 @@ private static void createAndShowGUI(Message message) {
}

public static void main(String[] args) {
final String fileName = retrieveFileName(args);
try {
final MessageBuilder builder = new DefaultMessageBuilder();
final Message message = builder.parseMessage(new FileInputStream(args[0]));
final Message message = builder.parseMessage(new FileInputStream(fileName));

javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
@@ -377,12 +378,19 @@ public void run() {
System.err.println("Usage: org.mime4j.samples.tree.MessageTree"
+ " path/to/message");
} catch (FileNotFoundException e) {
System.err.println("The file '" + args[0] + "' could not be found.");
System.err.println("The file '" + fileName + "' could not be found.");
} catch (IOException e) {
System.err.println("The file '" + args[0] + "' could not be read.");
System.err.println("The file '" + fileName + "' could not be read.");
} catch (MimeException e) {
System.err.println("The file '" + args[0] + "' is invalid.");
System.err.println("The file '" + fileName + "' is invalid.");
}
}

private static String retrieveFileName(String[] args) {
if (args.length < 1) {
return ClassLoader.getSystemResource("mime-example.msg").getFile();
}
return args[0];
}

}
@@ -0,0 +1,43 @@
Date: Fri, 27 Apr 2007 16:08:23 +0200
From: Foo Bar <bar@example.com>
MIME-Version: 1.0
To: foo@example.com
Subject: Here is the attachment I was waiting for.
Content-Type: multipart/mixed;
boundary="------------090404080405080108000909"

This is a multi-part message in MIME format.
--------------090404080405080108000909
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Body.

--------------090404080405080108000909
Content-Type: application/octet-stream;
name="data.bin"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="data.bin"

lLzmyQjBC2gw/hiUrcy/DDI5K6CBqFSs4NKCF67G5XBzOnSInWpZ+9Uv9IxFpz8rf871xAE+
+y0ZYES9LXDdP12svxsJ4hRsek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Lub/IY
KmU6Svelyk91XQF23dhbSqlLjeLlGjwtlHhqRuFASVIgIqcxbsrxa6CSmTrHmxr0NU5hmEWb
lBPvZwYZhZMu2c/yTirvknIijyTRjFmgwpB73uJHv0oQotC6myXTGNCc0MihBMOsDQs3Fhsl
JFQcH6VA0bze/FSZoGi+sM90lyrufQngenV1EVptFBx5DQYWEWXKOi2ZS6JQGYRh1R+EXA==
--------------090404080405080108000909--

0 comments on commit 6d2e664

Please sign in to comment.