Skip to content

Commit

Permalink
Issue #18: Format dates with the default locale
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrussler committed Sep 25, 2020
1 parent c5e2f34 commit bc45ae2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Usage: EMLtoPDFConverter [options] <EML-File>
```
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` <br>
Expand All @@ -75,5 +75,8 @@ Creates a windows setup in `build/innosetup`. This task needs the [Launch4j](htt
* `gradlew check` <br>
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.
23 changes: 18 additions & 5 deletions src/main/java/mimeparser/MimeMessageConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit bc45ae2

Please sign in to comment.