diff --git a/README.md b/README.md index 9b82db8..c379c69 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Usage: EMLtoPDFConverter [options] ``` E.g. ``java -jar emailconverter-2.1.1-all.jar example.eml`` (you need [wkhtmltopdf](http://wkhtmltopdf.org/) binary in the PATH) -### How to build +### How to Build You need to git clone this repository. The build will fail if you remove the .git folder (e.g. download this as zip from github). * `gradlew shadowJar`
@@ -75,5 +75,8 @@ Creates a windows setup in `build/innosetup`. This task needs the [Launch4j](htt * `gradlew check`
Executes the unit tests and generates various reports (jacoco, checkstyle, findbugs, jdepend, unit test report). +### Date Formatting +Dates are formatted with the default locale. You can change it, e.g. by passing the VM argument `-Duser.language=en-US` + ### License The code is available under the terms of the Apache V2 License. diff --git a/src/main/java/mimeparser/MimeMessageConverter.java b/src/main/java/mimeparser/MimeMessageConverter.java index a91a45a..6a942e9 100644 --- a/src/main/java/mimeparser/MimeMessageConverter.java +++ b/src/main/java/mimeparser/MimeMessageConverter.java @@ -22,14 +22,14 @@ import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.mail.Part; +import javax.mail.internet.MailDateFormat; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeUtility; @@ -90,6 +90,8 @@ public class MimeMessageConverter { private static final int CONVERSION_DPI = 300; private static final int IMAGE_QUALITY = 100; + private static final DateFormat DATE_FORMATTER = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); + /** * Execute a command and redirect its output to the standard output. * @param command list of the command and its parameters @@ -148,7 +150,18 @@ public static void convertToPdf(String emlPath, String pdfOutputPath, boolean hi } } - String sentDateStr = message.getHeader("date", null); + String sentDateStr = null; + try { + Date sentDate = message.getSentDate(); + sentDateStr = DATE_FORMATTER.format(sentDate); + } catch (Exception e) { + e.printStackTrace(); + } + + if (sentDateStr == null) { + Logger.error("Could not parse the date, fallback to raw value"); + sentDateStr = message.getHeader("date", null); + } /* ######### Parse the mime structure ######### */ Logger.info("Mime Structure of %s:\n%s", emlPath, MimeMessageParser.printStructure(message));