mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-12 18:52:21 -05:00
Improve attachment header processing, should create a dedicated parser
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@38 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
47ebe0e153
commit
c3e80f82fb
@ -809,6 +809,12 @@ public class ExchangeSession {
|
|||||||
writeBody(os, partHeader);
|
writeBody(os, partHeader);
|
||||||
} else {
|
} else {
|
||||||
Attachment attachment = attachmentsMap.get(partHeader.name);
|
Attachment attachment = attachmentsMap.get(partHeader.name);
|
||||||
|
|
||||||
|
// TODO : test if .eml extension could be stripped from attachment name directly
|
||||||
|
// try to get email attachment with .eml extension
|
||||||
|
if (attachment == null && partHeader.name != null) {
|
||||||
|
attachment = attachmentsMap.get(partHeader.name + ".eml");
|
||||||
|
}
|
||||||
// try to get attachment by index, only if no name found
|
// try to get attachment by index, only if no name found
|
||||||
if (attachment == null && partHeader.name == null) {
|
if (attachment == null && partHeader.name == null) {
|
||||||
attachment = attachmentsMap.get(String.valueOf(attachmentIndex));
|
attachment = attachmentsMap.get(String.valueOf(attachmentIndex));
|
||||||
@ -1126,6 +1132,8 @@ public class ExchangeSession {
|
|||||||
}
|
}
|
||||||
// decode slashes in attachment name
|
// decode slashes in attachment name
|
||||||
attachmentName = attachmentName.replaceAll("_xF8FF_", "/");
|
attachmentName = attachmentName.replaceAll("_xF8FF_", "/");
|
||||||
|
// trim attachment name
|
||||||
|
attachmentName = attachmentName.trim();
|
||||||
|
|
||||||
Attachment attachment = new Attachment();
|
Attachment attachment = new Attachment();
|
||||||
attachment.name = attachmentName;
|
attachment.name = attachmentName;
|
||||||
@ -1275,8 +1283,13 @@ public class ExchangeSession {
|
|||||||
int encodedIndex = header.indexOf("*=");
|
int encodedIndex = header.indexOf("*=");
|
||||||
if (encodedIndex >= 0) {
|
if (encodedIndex >= 0) {
|
||||||
StringBuffer decodedBuffer = new StringBuffer();
|
StringBuffer decodedBuffer = new StringBuffer();
|
||||||
decodedBuffer.append(header.substring(0, encodedIndex));
|
decodedBuffer.append(header.substring(0, header.indexOf("*")));
|
||||||
decodedBuffer.append('=');
|
decodedBuffer.append('=');
|
||||||
|
// if attachment name enclosed in quotes, increase encodedIndex
|
||||||
|
if (header.charAt(encodedIndex + 2) == '"') {
|
||||||
|
decodedBuffer.append('"');
|
||||||
|
encodedIndex++;
|
||||||
|
}
|
||||||
int encodedDataIndex = header.indexOf("''");
|
int encodedDataIndex = header.indexOf("''");
|
||||||
if (encodedDataIndex >= 0) {
|
if (encodedDataIndex >= 0) {
|
||||||
String encodedData = header.substring(encodedDataIndex + 2);
|
String encodedData = header.substring(encodedDataIndex + 2);
|
||||||
@ -1285,7 +1298,13 @@ public class ExchangeSession {
|
|||||||
header = decodedBuffer;
|
header = decodedBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringTokenizer tokenizer = new StringTokenizer(header.toString(), ";");
|
// internal header encoding ?
|
||||||
|
String decodedHeader = header.toString();
|
||||||
|
if (decodedHeader.indexOf("name*1*=") >= 0) {
|
||||||
|
decodedHeader = decodedHeader.replaceFirst("name\\*1\\*=", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer(decodedHeader, ";");
|
||||||
// first part is Content type
|
// first part is Content type
|
||||||
if (tokenizer.hasMoreTokens()) {
|
if (tokenizer.hasMoreTokens()) {
|
||||||
contentType = tokenizer.nextToken().trim();
|
contentType = tokenizer.nextToken().trim();
|
||||||
|
Loading…
Reference in New Issue
Block a user