mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Fixes issue 305
Support Content-Id header to show inline images.
This commit is contained in:
parent
df7cfdc3cf
commit
28d3967d0f
@ -18,6 +18,8 @@ public interface Part
|
||||
|
||||
public String getDisposition() throws MessagingException;
|
||||
|
||||
public String getContentId() throws MessagingException;
|
||||
|
||||
public String[] getHeader(String name) throws MessagingException;
|
||||
|
||||
public int getSize() throws MessagingException;
|
||||
|
@ -117,6 +117,26 @@ public class MimeBodyPart extends BodyPart
|
||||
}
|
||||
}
|
||||
|
||||
public String getContentId() throws MessagingException
|
||||
{
|
||||
String contentId = getFirstHeader(MimeHeader.HEADER_CONTENT_ID);
|
||||
if (contentId == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
int first = contentId.indexOf('<');
|
||||
int last = contentId.lastIndexOf('>');
|
||||
if (first != -1 && last != -1) {
|
||||
return contentId.substring(first+1, last);
|
||||
}
|
||||
else {
|
||||
return contentId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getMimeType() throws MessagingException
|
||||
{
|
||||
return MimeUtility.getHeaderParameter(getContentType(), null);
|
||||
|
@ -25,6 +25,7 @@ public class MimeHeader
|
||||
public static final String HEADER_CONTENT_TYPE = "Content-Type";
|
||||
public static final String HEADER_CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding";
|
||||
public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition";
|
||||
public static final String HEADER_CONTENT_ID = "Content-ID";
|
||||
|
||||
/**
|
||||
* Fields that should be omitted when writing the header using writeTo()
|
||||
|
@ -150,7 +150,10 @@ public class MimeMessage extends Message
|
||||
return contentDisposition;
|
||||
}
|
||||
}
|
||||
|
||||
public String getContentId() throws MessagingException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public String getMimeType() throws MessagingException
|
||||
{
|
||||
return MimeUtility.getHeaderParameter(getContentType(), null);
|
||||
|
@ -2015,6 +2015,8 @@ public class LocalStore extends Store implements Serializable
|
||||
MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA), ',');
|
||||
|
||||
String name = MimeUtility.getHeaderParameter(attachment.getContentType(), "name");
|
||||
String contentId = MimeUtility.getHeaderParameter(attachment.getContentId(), null);
|
||||
|
||||
String contentDisposition = MimeUtility.unfoldAndDecode(attachment.getDisposition());
|
||||
if (name == null && contentDisposition != null)
|
||||
{
|
||||
@ -2044,7 +2046,7 @@ public class LocalStore extends Store implements Serializable
|
||||
new String[] { Long.toString(attachmentId) });
|
||||
}
|
||||
|
||||
if (tempAttachmentFile != null)
|
||||
if (attachmentId != -1 && tempAttachmentFile != null)
|
||||
{
|
||||
File attachmentFile = new File(mAttachmentsDir, Long.toString(attachmentId));
|
||||
tempAttachmentFile.renameTo(attachmentFile);
|
||||
@ -2061,7 +2063,30 @@ public class LocalStore extends Store implements Serializable
|
||||
new String[] { Long.toString(attachmentId) });
|
||||
}
|
||||
|
||||
if (attachment instanceof LocalAttachmentBodyPart)
|
||||
/* The message has attachment with Content-ID */
|
||||
if (contentId != null && contentUri != null)
|
||||
{
|
||||
Cursor cursor = null;
|
||||
cursor = mDb.query("messages", new String[] { "html_content" }, "id = ?", new String[] { Long.toString(messageId) }, null, null, null);
|
||||
try {
|
||||
if (cursor.moveToNext())
|
||||
{
|
||||
String new_html;
|
||||
|
||||
new_html = cursor.getString(0);
|
||||
new_html = new_html.replaceAll("cid:" + contentId, contentUri.toString());
|
||||
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put("html_content", new_html);
|
||||
mDb.update("messages", cv, "id = ?", new String[] { Long.toString(messageId) });
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (cursor != null) { cursor.close(); }
|
||||
}
|
||||
}
|
||||
|
||||
if (attachmentId != -1 && attachment instanceof LocalAttachmentBodyPart)
|
||||
{
|
||||
((LocalAttachmentBodyPart) attachment).setAttachmentId(attachmentId);
|
||||
}
|
||||
@ -2290,15 +2315,8 @@ public class LocalStore extends Store implements Serializable
|
||||
html = htmlifyString(text);
|
||||
}
|
||||
|
||||
if (html.indexOf("cid:") != -1)
|
||||
{
|
||||
return html.replaceAll("cid:", "http://cid/");
|
||||
}
|
||||
else
|
||||
{
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
||||
public String htmlifyString(String text)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user