mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-15 14:05:05 -05:00
Use 8bit transfer encoding for the text body if SMTP server advertises 8BITMIME. In all other cases base64 is still used (including saved copies in IMAP "Sent" folder).
Feel free to revert this if anything breaks.
This commit is contained in:
parent
6480e78b97
commit
45036ae5c8
@ -143,4 +143,6 @@ public abstract class Message implements Part, Body
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract void saveChanges() throws MessagingException;
|
public abstract void saveChanges() throws MessagingException;
|
||||||
|
|
||||||
|
public abstract void setEncoding(String encoding);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ package com.fsck.k9.mail;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.fsck.k9.mail.internet.MimeHeader;
|
||||||
|
import com.fsck.k9.mail.internet.TextBody;
|
||||||
|
|
||||||
public abstract class Multipart implements Body
|
public abstract class Multipart implements Body
|
||||||
{
|
{
|
||||||
protected Part mParent;
|
protected Part mParent;
|
||||||
@ -55,4 +58,25 @@ public abstract class Multipart implements Body
|
|||||||
{
|
{
|
||||||
this.mParent = parent;
|
this.mParent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEncoding(String encoding)
|
||||||
|
{
|
||||||
|
for (BodyPart part : mParts)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Body body = part.getBody();
|
||||||
|
if (body instanceof TextBody)
|
||||||
|
{
|
||||||
|
part.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, encoding);
|
||||||
|
((TextBody)body).setEncoding(encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (MessagingException e)
|
||||||
|
{
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,9 +369,9 @@ public class MimeMessage extends Message
|
|||||||
{
|
{
|
||||||
this.mBody = body;
|
this.mBody = body;
|
||||||
setHeader("MIME-Version", "1.0");
|
setHeader("MIME-Version", "1.0");
|
||||||
if (body instanceof com.fsck.k9.mail.Multipart)
|
if (body instanceof Multipart)
|
||||||
{
|
{
|
||||||
com.fsck.k9.mail.Multipart multipart = ((com.fsck.k9.mail.Multipart)body);
|
Multipart multipart = ((Multipart)body);
|
||||||
multipart.setParent(this);
|
multipart.setParent(this);
|
||||||
setHeader(MimeHeader.HEADER_CONTENT_TYPE, multipart.getContentType());
|
setHeader(MimeHeader.HEADER_CONTENT_TYPE, multipart.getContentType());
|
||||||
}
|
}
|
||||||
@ -431,6 +431,19 @@ public class MimeMessage extends Message
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEncoding(String encoding)
|
||||||
|
{
|
||||||
|
if (mBody instanceof Multipart)
|
||||||
|
{
|
||||||
|
((Multipart)mBody).setEncoding(encoding);
|
||||||
|
}
|
||||||
|
else if (mBody instanceof TextBody)
|
||||||
|
{
|
||||||
|
setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, encoding);
|
||||||
|
((TextBody)mBody).setEncoding(encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MimeMessageBuilder implements ContentHandler
|
class MimeMessageBuilder implements ContentHandler
|
||||||
{
|
{
|
||||||
private Stack stack = new Stack();
|
private Stack stack = new Stack();
|
||||||
|
@ -9,7 +9,8 @@ import java.io.*;
|
|||||||
|
|
||||||
public class TextBody implements Body
|
public class TextBody implements Body
|
||||||
{
|
{
|
||||||
String mBody;
|
private String mBody;
|
||||||
|
private String mEncoding;
|
||||||
|
|
||||||
public TextBody(String body)
|
public TextBody(String body)
|
||||||
{
|
{
|
||||||
@ -18,12 +19,19 @@ public class TextBody implements Body
|
|||||||
|
|
||||||
public void writeTo(OutputStream out) throws IOException, MessagingException
|
public void writeTo(OutputStream out) throws IOException, MessagingException
|
||||||
{
|
{
|
||||||
if (mBody!=null)
|
if (mBody != null)
|
||||||
{
|
{
|
||||||
byte[] bytes = mBody.getBytes("UTF-8");
|
byte[] bytes = mBody.getBytes("UTF-8");
|
||||||
|
if ("8bit".equals(mEncoding))
|
||||||
|
{
|
||||||
|
out.write(bytes);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
out.write(Base64.encodeBase64Chunked(bytes));
|
out.write(Base64.encodeBase64Chunked(bytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the text of the body in it's unencoded format.
|
* Get the text of the body in it's unencoded format.
|
||||||
@ -57,4 +65,9 @@ public class TextBody implements Body
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEncoding(String encoding)
|
||||||
|
{
|
||||||
|
mEncoding = encoding;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ public class SmtpTransport extends Transport
|
|||||||
PeekableInputStream mIn;
|
PeekableInputStream mIn;
|
||||||
|
|
||||||
OutputStream mOut;
|
OutputStream mOut;
|
||||||
|
private boolean m8bitEncodingAllowed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* smtp://user:password@server:port CONNECTION_SECURITY_NONE
|
* smtp://user:password@server:port CONNECTION_SECURITY_NONE
|
||||||
@ -184,6 +185,8 @@ public class SmtpTransport extends Transport
|
|||||||
|
|
||||||
List<String> results = executeSimpleCommand("EHLO " + localHost);
|
List<String> results = executeSimpleCommand("EHLO " + localHost);
|
||||||
|
|
||||||
|
m8bitEncodingAllowed = results.contains("8BITMIME");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO may need to add code to fall back to HELO I switched it from
|
* TODO may need to add code to fall back to HELO I switched it from
|
||||||
* using HELO on non STARTTLS connections because of AOL's mail
|
* using HELO on non STARTTLS connections because of AOL's mail
|
||||||
@ -285,10 +288,19 @@ public class SmtpTransport extends Transport
|
|||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
open();
|
open();
|
||||||
|
|
||||||
|
if (m8bitEncodingAllowed)
|
||||||
|
{
|
||||||
|
//TODO: Make sure that we don't have lines that are longer than
|
||||||
|
// 998 bytes (don't count characters!)
|
||||||
|
message.setEncoding("8bit");
|
||||||
|
}
|
||||||
|
|
||||||
Address[] from = message.getFrom();
|
Address[] from = message.getFrom();
|
||||||
boolean possibleSend = false;
|
boolean possibleSend = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//TODO: Add BODY=8BITMIME parameter if appropriate?
|
||||||
executeSimpleCommand("MAIL FROM: " + "<" + from[0].getAddress() + ">");
|
executeSimpleCommand("MAIL FROM: " + "<" + from[0].getAddress() + ">");
|
||||||
for (Address address : message.getRecipients(RecipientType.TO))
|
for (Address address : message.getRecipients(RecipientType.TO))
|
||||||
{
|
{
|
||||||
@ -304,9 +316,13 @@ public class SmtpTransport extends Transport
|
|||||||
}
|
}
|
||||||
message.setRecipients(RecipientType.BCC, null);
|
message.setRecipients(RecipientType.BCC, null);
|
||||||
executeSimpleCommand("DATA");
|
executeSimpleCommand("DATA");
|
||||||
|
|
||||||
|
//TODO: Data stuffing (RFC 821 4.5.2.)
|
||||||
EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream(
|
EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream(
|
||||||
new BufferedOutputStream(mOut, 1024));
|
new BufferedOutputStream(mOut, 1024));
|
||||||
|
|
||||||
message.writeTo(msgOut);
|
message.writeTo(msgOut);
|
||||||
|
|
||||||
// We use BufferedOutputStream. So make sure to call flush() !
|
// We use BufferedOutputStream. So make sure to call flush() !
|
||||||
msgOut.flush();
|
msgOut.flush();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user