Commit c5260a03 authored by Hussein's avatar Hussein

Merge branch 'bug/P4A-720' into develop

parents 6eafc352 d952977f
......@@ -65,7 +65,7 @@ class PEpMessageBuilder {
// - plain text body if html above
// - many attachments (of type binarymemoryblob (hopefully ;-)).
Body b = mm.getBody();
Vector<Blob> attachments = new Vector<Blob>();
Vector<Blob> attachments = new Vector<>();
if(!(b instanceof MimeMultipart)) { //FIXME: Don't do this assumption (if not Multipart then plain or html text)
......@@ -78,13 +78,7 @@ class PEpMessageBuilder {
// return;
}
String charset = MimeUtility.getHeaderParameter(mm.getContentType(), "charset");
if (charset == null || !Charset.isSupported(charset)) {
// failback when the header doesn't have charset parameter or it is invalid, defaults to UTF-8
// FIXME: charset, trate non text bod4y types like application/pgp-keys
charset = Charset.defaultCharset().name();
}
String charset = getMessageCharset();
String text = new String(PEpUtils.extractBodyContent(b), charset);
if(mm.isMimeType("text/html")) {
pEpMsg.setLongmsgFormatted(text);
......@@ -100,6 +94,17 @@ class PEpMessageBuilder {
pEpMsg.setAttachments(attachments);
}
private String getMessageCharset() {
String charset = MimeUtility.getHeaderParameter(mm.getContentType(), "charset");
if (charset == null || !Charset.isSupported(charset)) {
// failback when the header doesn't have charset parameter or it is invalid, defaults to UTF-8
// FIXME: charset, treat non text body types like application/pgp-keys
charset = Charset.defaultCharset().name();
}
return charset;
}
private void handleMultipart(Message pEpMsg, MimeMultipart mmp, Vector<Blob> attachments) throws MessagingException, IOException, UnsupportedEncodingException {
int nrOfParts = mmp.getBodyParts().size();
for (int part = 0; part < nrOfParts; part++) {
......@@ -118,13 +123,9 @@ class PEpMessageBuilder {
boolean plain = mbp.isMimeType("text/plain");
if (plain || mbp.isMimeType("text/html")) {
String charset = MimeUtility.getHeaderParameter(mbp.getContentType(), "charset");
String text;
if (charset != null) {
text = new String(PEpUtils.extractBodyContent(mbp_body), charset);
} else {
text = new String(PEpUtils.extractBodyContent(mbp_body));
}
String charset = getMessageCharset();
String text = new String(PEpUtils.extractBodyContent(mbp_body), charset);
if (plain) {
String longmsg = pEpMsg.getLongmsg();
if (longmsg != null) {
......@@ -231,7 +232,7 @@ class PEpMessageBuilder {
}
private Vector<String> createMessageReferences(String[] references) {
Vector<String> rv = new Vector<String>();
Vector<String> rv = new Vector<>();
if(references != null)
for(String s : references)
rv.add(s);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment