mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-02 14:02:17 -05:00
Allow emoji input.
Signed-off-by: HIRANO Takahito <hiranotaka@zng.info>
This commit is contained in:
parent
d25f12fa16
commit
2daf8eaec8
@ -377,10 +377,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
EditText lowerSignature = (EditText)findViewById(R.id.lower_signature);
|
EditText lowerSignature = (EditText)findViewById(R.id.lower_signature);
|
||||||
|
|
||||||
mMessageContentView = (EditText)findViewById(R.id.message_content);
|
mMessageContentView = (EditText)findViewById(R.id.message_content);
|
||||||
|
mMessageContentView.getInputExtras(true).putBoolean("allowEmoji", true);
|
||||||
mAttachments = (LinearLayout)findViewById(R.id.attachments);
|
mAttachments = (LinearLayout)findViewById(R.id.attachments);
|
||||||
mQuotedTextBar = findViewById(R.id.quoted_text_bar);
|
mQuotedTextBar = findViewById(R.id.quoted_text_bar);
|
||||||
mQuotedTextDelete = (ImageButton)findViewById(R.id.quoted_text_delete);
|
mQuotedTextDelete = (ImageButton)findViewById(R.id.quoted_text_delete);
|
||||||
mQuotedText = (EditText)findViewById(R.id.quoted_text);
|
mQuotedText = (EditText)findViewById(R.id.quoted_text);
|
||||||
|
mQuotedText.getInputExtras(true).putBoolean("allowEmoji", true);
|
||||||
|
|
||||||
TextWatcher watcher = new TextWatcher()
|
TextWatcher watcher = new TextWatcher()
|
||||||
{
|
{
|
||||||
|
@ -207,6 +207,8 @@ public abstract class Message implements Part, Body
|
|||||||
|
|
||||||
public abstract void setEncoding(String encoding) throws UnavailableStorageException;
|
public abstract void setEncoding(String encoding) throws UnavailableStorageException;
|
||||||
|
|
||||||
|
public abstract void setCharset(String charset) throws MessagingException;
|
||||||
|
|
||||||
public MessageReference makeMessageReference()
|
public MessageReference makeMessageReference()
|
||||||
{
|
{
|
||||||
if (mReference == null)
|
if (mReference == null)
|
||||||
|
@ -4,6 +4,7 @@ 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.MimeHeader;
|
||||||
|
import com.fsck.k9.mail.internet.MimeUtility;
|
||||||
import com.fsck.k9.mail.internet.TextBody;
|
import com.fsck.k9.mail.internet.TextBody;
|
||||||
|
|
||||||
public abstract class Multipart implements Body
|
public abstract class Multipart implements Body
|
||||||
@ -83,4 +84,18 @@ public abstract class Multipart implements Body
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCharset(String charset) throws MessagingException
|
||||||
|
{
|
||||||
|
if (mParts.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
BodyPart part = mParts.get(0);
|
||||||
|
Body body = part.getBody();
|
||||||
|
if (body instanceof TextBody)
|
||||||
|
{
|
||||||
|
MimeUtility.setCharset(charset, part);
|
||||||
|
((TextBody)body).setCharset(charset);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -501,6 +501,19 @@ public class MimeMessage extends Message
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCharset(String charset) throws MessagingException
|
||||||
|
{
|
||||||
|
if (mBody instanceof Multipart)
|
||||||
|
{
|
||||||
|
((Multipart)mBody).setCharset(charset);
|
||||||
|
}
|
||||||
|
else if (mBody instanceof TextBody)
|
||||||
|
{
|
||||||
|
MimeUtility.setCharset(charset, this);
|
||||||
|
((TextBody)mBody).setCharset(charset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MimeMessageBuilder implements ContentHandler
|
class MimeMessageBuilder implements ContentHandler
|
||||||
{
|
{
|
||||||
private Stack<Object> stack = new Stack<Object>();
|
private Stack<Object> stack = new Stack<Object>();
|
||||||
|
@ -1211,6 +1211,18 @@ public class MimeUtility
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getCharsetFromAddress(String address)
|
||||||
|
{
|
||||||
|
String variant = getJisVariantFromAddress(address);
|
||||||
|
if (variant != null)
|
||||||
|
{
|
||||||
|
String charset = "x-" + variant + "-shift_jis-2007";
|
||||||
|
if (Charset.isSupported(charset))
|
||||||
|
return charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "UTF-8";
|
||||||
|
}
|
||||||
|
|
||||||
public static String getMimeTypeByExtension(String filename)
|
public static String getMimeTypeByExtension(String filename)
|
||||||
{
|
{
|
||||||
@ -1917,4 +1929,19 @@ public class MimeUtility
|
|||||||
default: return codePoint;
|
default: return codePoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setCharset(String charset, Part part) throws MessagingException
|
||||||
|
{
|
||||||
|
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE,
|
||||||
|
part.getMimeType() + ";\n charset=" + getExternalCharset(charset));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getExternalCharset(String charset)
|
||||||
|
{
|
||||||
|
if (charset.length() > 17 && charset.startsWith("x-") &&
|
||||||
|
charset.endsWith("-shift_jis-2007"))
|
||||||
|
return "shift_jis";
|
||||||
|
|
||||||
|
return charset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ public class TextBody implements Body
|
|||||||
|
|
||||||
private String mBody;
|
private String mBody;
|
||||||
private String mEncoding;
|
private String mEncoding;
|
||||||
|
private String mCharset = "UTF-8";
|
||||||
|
|
||||||
public TextBody(String body)
|
public TextBody(String body)
|
||||||
{
|
{
|
||||||
@ -28,7 +29,7 @@ public class TextBody implements Body
|
|||||||
{
|
{
|
||||||
if (mBody != null)
|
if (mBody != null)
|
||||||
{
|
{
|
||||||
byte[] bytes = mBody.getBytes("UTF-8");
|
byte[] bytes = mBody.getBytes(mCharset);
|
||||||
if ("8bit".equals(mEncoding))
|
if ("8bit".equals(mEncoding))
|
||||||
{
|
{
|
||||||
out.write(bytes);
|
out.write(bytes);
|
||||||
@ -52,7 +53,7 @@ public class TextBody implements Body
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an InputStream that reads this body's text in UTF-8 format.
|
* Returns an InputStream that reads this body's text.
|
||||||
*/
|
*/
|
||||||
public InputStream getInputStream() throws MessagingException
|
public InputStream getInputStream() throws MessagingException
|
||||||
{
|
{
|
||||||
@ -61,7 +62,7 @@ public class TextBody implements Body
|
|||||||
byte[] b;
|
byte[] b;
|
||||||
if (mBody!=null)
|
if (mBody!=null)
|
||||||
{
|
{
|
||||||
b = mBody.getBytes("UTF-8");
|
b = mBody.getBytes(mCharset);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -79,4 +80,9 @@ public class TextBody implements Body
|
|||||||
{
|
{
|
||||||
mEncoding = encoding;
|
mEncoding = encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCharset(String charset)
|
||||||
|
{
|
||||||
|
mCharset = charset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
|
|||||||
import com.fsck.k9.mail.filter.LineWrapOutputStream;
|
import com.fsck.k9.mail.filter.LineWrapOutputStream;
|
||||||
import com.fsck.k9.mail.filter.PeekableInputStream;
|
import com.fsck.k9.mail.filter.PeekableInputStream;
|
||||||
import com.fsck.k9.mail.filter.SmtpDataStuffing;
|
import com.fsck.k9.mail.filter.SmtpDataStuffing;
|
||||||
|
import com.fsck.k9.mail.internet.MimeUtility;
|
||||||
import com.fsck.k9.mail.store.TrustManagerFactory;
|
import com.fsck.k9.mail.store.TrustManagerFactory;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
@ -27,6 +28,8 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import org.apache.commons.codec.binary.Hex;
|
import org.apache.commons.codec.binary.Hex;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SmtpTransport extends Transport
|
public class SmtpTransport extends Transport
|
||||||
@ -308,13 +311,45 @@ public class SmtpTransport extends Transport
|
|||||||
@Override
|
@Override
|
||||||
public void sendMessage(Message message) throws MessagingException
|
public void sendMessage(Message message) throws MessagingException
|
||||||
{
|
{
|
||||||
|
ArrayList<Address> addresses = new ArrayList<Address>();
|
||||||
|
{
|
||||||
|
addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO)));
|
||||||
|
addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC)));
|
||||||
|
addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC)));
|
||||||
|
}
|
||||||
|
message.setRecipients(RecipientType.BCC, null);
|
||||||
|
|
||||||
|
HashMap<String, ArrayList<String>> charsetAddressesMap =
|
||||||
|
new HashMap<String, ArrayList<String>>();
|
||||||
|
for (Address address : addresses)
|
||||||
|
{
|
||||||
|
String addressString = address.getAddress();
|
||||||
|
String charset = MimeUtility.getCharsetFromAddress(addressString);
|
||||||
|
ArrayList<String> addressesOfCharset = charsetAddressesMap.get(charset);
|
||||||
|
if (addressesOfCharset == null)
|
||||||
|
{
|
||||||
|
addressesOfCharset = new ArrayList<String>();
|
||||||
|
charsetAddressesMap.put(charset, addressesOfCharset);
|
||||||
|
}
|
||||||
|
addressesOfCharset.add(addressString);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (HashMap.Entry<String, ArrayList<String>> charsetAddressesMapEntry :
|
||||||
|
charsetAddressesMap.entrySet())
|
||||||
|
{
|
||||||
|
String charset = charsetAddressesMapEntry.getKey();
|
||||||
|
ArrayList<String> addressesOfCharset = charsetAddressesMapEntry.getValue();
|
||||||
|
message.setCharset(charset);
|
||||||
|
sendMessageTo(addressesOfCharset, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageTo(ArrayList<String> addresses, Message message)
|
||||||
|
throws MessagingException{
|
||||||
close();
|
close();
|
||||||
open();
|
open();
|
||||||
|
|
||||||
if (m8bitEncodingAllowed)
|
message.setEncoding(m8bitEncodingAllowed ? "8bit" : null);
|
||||||
{
|
|
||||||
message.setEncoding("8bit");
|
|
||||||
}
|
|
||||||
|
|
||||||
Address[] from = message.getFrom();
|
Address[] from = message.getFrom();
|
||||||
boolean possibleSend = false;
|
boolean possibleSend = false;
|
||||||
@ -322,19 +357,10 @@ public class SmtpTransport extends Transport
|
|||||||
{
|
{
|
||||||
//TODO: Add BODY=8BITMIME parameter if appropriate?
|
//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 (String address : addresses)
|
||||||
{
|
{
|
||||||
executeSimpleCommand("RCPT TO: " + "<" + address.getAddress() + ">");
|
executeSimpleCommand("RCPT TO: " + "<" + address + ">");
|
||||||
}
|
}
|
||||||
for (Address address : message.getRecipients(RecipientType.CC))
|
|
||||||
{
|
|
||||||
executeSimpleCommand("RCPT TO: " + "<" + address.getAddress() + ">");
|
|
||||||
}
|
|
||||||
for (Address address : message.getRecipients(RecipientType.BCC))
|
|
||||||
{
|
|
||||||
executeSimpleCommand("RCPT TO: " + "<" + address.getAddress() + ">");
|
|
||||||
}
|
|
||||||
message.setRecipients(RecipientType.BCC, null);
|
|
||||||
executeSimpleCommand("DATA");
|
executeSimpleCommand("DATA");
|
||||||
|
|
||||||
EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream(
|
EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream(
|
||||||
|
Loading…
Reference in New Issue
Block a user