You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2021/06/29 01:34:29 UTC

[james-mime4j] 01/08: [EXAMPLES] MessageTree should be easy to launch from an IDE

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-mime4j.git

commit 6d2e66423fa50fec84b4684ed94819ffd18bab31
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Jun 24 14:34:31 2021 +0700

    [EXAMPLES] MessageTree should be easy to launch from an IDE
    
    We can default to a local resource if no argument is provided.
---
 .../james/mime4j/samples/tree/MessageTree.java     | 16 ++++++--
 examples/src/main/resources/mime-example.msg       | 43 ++++++++++++++++++++++
 2 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java b/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
index 17bd138..9cd7fd2 100644
--- a/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
+++ b/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
@@ -362,9 +362,10 @@ public class MessageTree extends JPanel implements TreeSelectionListener {
     }
 
     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 class MessageTree extends JPanel implements TreeSelectionListener {
             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];
+    }
+
 }
diff --git a/examples/src/main/resources/mime-example.msg b/examples/src/main/resources/mime-example.msg
new file mode 100644
index 0000000..5ee0dd5
--- /dev/null
+++ b/examples/src/main/resources/mime-example.msg
@@ -0,0 +1,43 @@
+Date: Fri, 27 Apr 2007 16:08:23 +0200
+From: Foo Bar <ba...@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+
++y0ZYES9LXDdP12svxsJ4hRsekH2HJ953Kglb3hxko7LlPlxeDX15FKH0VBE8Ggr4RbwoP+c
+mkyyhKyaiV95ycRzRd5ozVDGhmW/eQIZgw3nYJOt99vyPxolkHD8PLevmx4PTteIO4hIWjHG
+XtKCTNwBG0z4cW3EOHWxsvo5v6JUEueDaxfFWKrA/MWP2TkYREXMj+q0XC4MpKZgIjqRL/9E
+s6gqpJTb4eyYL6FBdgrNeLqDQ5ozgu1zaQi9+yuoCABIHKCEPv32W+9Wt/MjMqCnKdk+Zdsw
+ZBna0Fq/168oqKh0S++trpgndHvWZWojNY+rDqnl5o3T9IvTgTuG8IHPSxUODbWFy1vim+jU
+eGNpCfko6DGo5oBCKzg5BTlz2kAED6F1X6/a+w0/9zGJZJ9Tyg6fb8LE7OwDFp1pH99x6SgR
+xa+IFHoXhbjRzkRi/ZRZKrqm4jxvhFTXlx9w70SL0GawHUwuNOgEUKJM75ADmDEEtRB0pQ8S
+RPoKn/b1RLGQPsvHzcqtSJljgbMMBmoiBFkAnzopnVn1RJfBzI6x9YcXtNqtJCTXdHzPg4D+
+WhwkCB0AF7W8EoVqvmlP2g0vAdPz4gR8+I6AFdGQtC52CMhX/1mHAeTjDCnuvTzZvKrACcVB
+9Ea12w10KLYbsgAr2+2vfAdiLUdUZDKHPPtWC+lSrvkTJtivU+YOSw7PCkWF7BIC7pTdp7Wu
+tqGCmVo0eHKfJxXcpkH++9ALeAQ8tfQw9K20JJW18fSAw/hs8fxs5FWjhNpYpUvQlqznN98K
+/pnaXQo373NufYHy1+yT3sSVEwBbClv7yOjrYrmyRe6ojw+ZxXziWk8r+VkFpotwvgW41vOu
+vkhd94rzr1Mj7WNEssTrJOQC5Uda2DPZkHgxBbZch2ru65Jmivr493iTF157c6MZhJUSW+P5
+Xd+WoDrUwzcpMx7QdyZaNSPVsL7uD4xOKoqm4OcdyzEj4qqDvBLA0TJ8sQ4Fp0A5h7nNTuoU
+vxKMan0J4rRKc7T4eswuLEaTPCDtKpsmlTS+rG4jPaCOlPM++qrI6VMgJBZOL/zG7mLub/IY
+KmU6Svelyk91XQF23dhbSqlLjeLlGjwtlHhqRuFASVIgIqcxbsrxa6CSmTrHmxr0NU5hmEWb
+lBPvZwYZhZMu2c/yTirvknIijyTRjFmgwpB73uJHv0oQotC6myXTGNCc0MihBMOsDQs3Fhsl
+JFQcH6VA0bze/FSZoGi+sM90lyrufQngenV1EVptFBx5DQYWEWXKOi2ZS6JQGYRh1R+EXA==
+--------------090404080405080108000909--
+

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org