2009-12-14 21:50:53 -05:00
package com.fsck.k9.activity ;
2008-11-01 17:32:06 -04:00
2011-05-10 11:54:17 -04:00
2012-11-16 12:28:40 -05:00
import android.annotation.TargetApi ;
2010-07-04 13:46:55 -04:00
import android.app.AlertDialog ;
2012-03-22 17:17:10 -04:00
import android.app.AlertDialog.Builder ;
2010-07-04 13:46:55 -04:00
import android.app.Dialog ;
2014-01-26 11:02:08 -05:00
import android.content.ClipData ;
2008-11-01 17:32:06 -04:00
import android.content.Context ;
2010-07-04 13:46:55 -04:00
import android.content.DialogInterface ;
2008-11-01 17:32:06 -04:00
import android.content.Intent ;
import android.content.pm.ActivityInfo ;
import android.net.Uri ;
2010-07-21 23:40:22 -04:00
import android.os.AsyncTask ;
2012-11-16 12:28:40 -05:00
import android.os.Build ;
2008-11-01 17:32:06 -04:00
import android.os.Bundle ;
import android.os.Handler ;
import android.os.Parcelable ;
2013-08-14 12:05:57 -04:00
import android.support.v4.app.LoaderManager ;
import android.support.v4.content.Loader ;
2014-02-15 16:05:18 -05:00
import android.text.TextUtils ;
2012-05-20 16:44:32 -04:00
import android.text.TextWatcher ;
2008-11-01 17:32:06 -04:00
import android.text.util.Rfc822Tokenizer ;
2013-10-08 19:14:08 -04:00
import android.util.AttributeSet ;
2008-11-01 17:32:06 -04:00
import android.util.Log ;
2012-01-11 19:05:01 -05:00
import android.util.TypedValue ;
2012-03-22 17:17:10 -04:00
import android.view.LayoutInflater ;
2012-07-12 12:29:41 -04:00
import com.actionbarsherlock.view.Menu ;
import com.actionbarsherlock.view.MenuItem ;
2012-08-24 12:39:23 -04:00
import com.actionbarsherlock.view.Window ;
2012-09-15 21:16:29 -04:00
import android.view.ContextThemeWrapper ;
2008-11-01 17:32:06 -04:00
import android.view.View ;
import android.view.View.OnClickListener ;
2012-03-22 17:17:10 -04:00
import android.view.ViewGroup ;
2011-01-12 18:48:28 -05:00
import android.webkit.WebView ;
2012-05-20 16:44:32 -04:00
import android.webkit.WebViewClient ;
2008-11-01 17:32:06 -04:00
import android.widget.AutoCompleteTextView.Validator ;
2012-03-22 17:17:10 -04:00
import android.widget.BaseAdapter ;
2011-05-17 11:00:16 -04:00
import android.widget.Button ;
2010-07-27 08:10:09 -04:00
import android.widget.CheckBox ;
2012-05-20 16:44:32 -04:00
import android.widget.CompoundButton ;
import android.widget.CompoundButton.OnCheckedChangeListener ;
2010-07-27 08:10:09 -04:00
import android.widget.EditText ;
import android.widget.ImageButton ;
import android.widget.LinearLayout ;
import android.widget.MultiAutoCompleteTextView ;
import android.widget.TextView ;
import android.widget.Toast ;
import com.fsck.k9.Account ;
2011-01-12 18:48:28 -05:00
import com.fsck.k9.Account.MessageFormat ;
2012-05-20 16:44:32 -04:00
import com.fsck.k9.Account.QuoteStyle ;
2010-07-27 08:10:09 -04:00
import com.fsck.k9.EmailAddressAdapter ;
import com.fsck.k9.EmailAddressValidator ;
2012-01-11 19:05:01 -05:00
import com.fsck.k9.FontSizes ;
2010-07-27 08:10:09 -04:00
import com.fsck.k9.Identity ;
import com.fsck.k9.K9 ;
import com.fsck.k9.Preferences ;
import com.fsck.k9.R ;
2013-08-14 12:05:57 -04:00
import com.fsck.k9.activity.loader.AttachmentContentLoader ;
import com.fsck.k9.activity.loader.AttachmentInfoLoader ;
import com.fsck.k9.activity.misc.Attachment ;
2010-05-19 14:17:06 -04:00
import com.fsck.k9.controller.MessagingController ;
import com.fsck.k9.controller.MessagingListener ;
2010-07-27 08:10:09 -04:00
import com.fsck.k9.crypto.CryptoProvider ;
2010-08-22 05:51:17 -04:00
import com.fsck.k9.crypto.PgpData ;
2013-09-24 21:46:11 -04:00
import com.fsck.k9.fragment.ProgressDialogFragment ;
2012-04-08 12:32:04 -04:00
import com.fsck.k9.helper.ContactItem ;
2010-10-30 16:35:49 -04:00
import com.fsck.k9.helper.Contacts ;
2012-05-20 16:44:32 -04:00
import com.fsck.k9.helper.HtmlConverter ;
import com.fsck.k9.helper.StringUtils ;
2010-05-19 14:17:06 -04:00
import com.fsck.k9.helper.Utility ;
2012-05-20 16:44:32 -04:00
import com.fsck.k9.mail.Address ;
import com.fsck.k9.mail.Body ;
import com.fsck.k9.mail.Flag ;
import com.fsck.k9.mail.Message ;
2009-12-14 21:50:53 -05:00
import com.fsck.k9.mail.Message.RecipientType ;
2012-05-20 16:44:32 -04:00
import com.fsck.k9.mail.MessagingException ;
import com.fsck.k9.mail.Multipart ;
import com.fsck.k9.mail.Part ;
2010-07-27 08:10:09 -04:00
import com.fsck.k9.mail.internet.MimeBodyPart ;
import com.fsck.k9.mail.internet.MimeHeader ;
import com.fsck.k9.mail.internet.MimeMessage ;
import com.fsck.k9.mail.internet.MimeMultipart ;
import com.fsck.k9.mail.internet.MimeUtility ;
import com.fsck.k9.mail.internet.TextBody ;
2009-12-14 21:50:53 -05:00
import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBody ;
2013-09-24 21:54:35 -04:00
import com.fsck.k9.mail.store.LocalStore.TempFileBody ;
import com.fsck.k9.mail.store.LocalStore.TempFileMessageBody ;
2012-05-20 16:44:32 -04:00
import com.fsck.k9.view.MessageWebView ;
import org.apache.james.mime4j.codec.EncoderUtil ;
Don't base64 encode attachments of type message/rfc822.
The problem: Receive a message with an attachment of type message/rfc822
and forward it. When the message is sent, K-9 Mail uses base64 encoding
for the attachment. (Alternatively, you could compose a new message and
add such an attachment from a file using a filing-picking app, but that is
not 100% effective because the app may not choose the correct
message/rfc822 MIME type for the attachment.)
Such encoding is prohibited per RFC 2046 (5.2.1) and RFC 2045 (6.4). Only
8bit or 7bit encoding is permitted for attachments of type message/rfc822.
Thunderbird refuses to decode such attachments. All that is shown is the
base64 encoded body.
This commit implements LocalAttachmentBody.setEncoding. If an attachment
to a newly composed message is itself a message, then setEncoding("8bit")
is called, otherwise setEncoding("base64") is called for the attachment.
Similar behavior occurs when an attachment is retrieved from LocalStore.
The setEncoding method was added to the Body interface, since all
implementations of Body now declare the method.
The problem here differs from that in the preceding commit: Here, the
encoding problem occurs on sending, not on receipt. Here, the entire
message (headers and body) is base64 encoded, not just the body. Here,
the headers correctly identify the encoding used; it's just that the RFC
does not permit such encoding of attached messages. The problem here
could in fact occur in combination with the preceding problem.
2013-09-01 16:25:09 -04:00
import org.apache.james.mime4j.util.MimeUtil ;
2012-05-20 16:44:32 -04:00
import org.htmlcleaner.CleanerProperties ;
import org.htmlcleaner.HtmlCleaner ;
import org.htmlcleaner.SimpleHtmlSerializer ;
import org.htmlcleaner.TagNode ;
2013-10-10 16:51:39 -04:00
import java.text.DateFormat ;
2012-05-20 16:44:32 -04:00
import java.util.ArrayList ;
import java.util.Arrays ;
2012-11-16 12:28:40 -05:00
import java.util.Collections ;
2012-05-20 16:44:32 -04:00
import java.util.Date ;
import java.util.HashMap ;
2012-11-16 12:28:40 -05:00
import java.util.HashSet ;
2012-05-20 16:44:32 -04:00
import java.util.List ;
import java.util.Locale ;
import java.util.Map ;
2012-11-16 12:28:40 -05:00
import java.util.Set ;
2012-05-20 16:44:32 -04:00
import java.util.StringTokenizer ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
2009-12-09 22:16:42 -05:00
2013-09-24 21:46:11 -04:00
public class MessageCompose extends K9Activity implements OnClickListener ,
ProgressDialogFragment . CancelListener {
2010-07-04 13:46:55 -04:00
private static final int DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE = 1 ;
2011-11-19 19:05:24 -05:00
private static final int DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED = 2 ;
2011-11-21 02:59:51 -05:00
private static final int DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY = 3 ;
2012-02-02 16:56:56 -05:00
private static final int DIALOG_CONFIRM_DISCARD_ON_BACK = 4 ;
2012-03-22 17:17:10 -04:00
private static final int DIALOG_CHOOSE_IDENTITY = 5 ;
2010-07-04 13:46:55 -04:00
2012-01-21 23:14:58 -05:00
private static final long INVALID_DRAFT_ID = MessagingController . INVALID_MESSAGE_ID ;
2011-11-14 18:28:45 -05:00
private static final String ACTION_COMPOSE = " com.fsck.k9.intent.action.COMPOSE " ;
2009-12-14 21:50:53 -05:00
private static final String ACTION_REPLY = " com.fsck.k9.intent.action.REPLY " ;
private static final String ACTION_REPLY_ALL = " com.fsck.k9.intent.action.REPLY_ALL " ;
private static final String ACTION_FORWARD = " com.fsck.k9.intent.action.FORWARD " ;
private static final String ACTION_EDIT_DRAFT = " com.fsck.k9.intent.action.EDIT_DRAFT " ;
2008-11-01 17:32:06 -04:00
private static final String EXTRA_ACCOUNT = " account " ;
2010-07-27 08:10:09 -04:00
private static final String EXTRA_MESSAGE_BODY = " messageBody " ;
2010-07-21 23:15:28 -04:00
private static final String EXTRA_MESSAGE_REFERENCE = " message_reference " ;
2008-11-01 17:32:06 -04:00
private static final String STATE_KEY_ATTACHMENTS =
2009-12-14 21:50:53 -05:00
" com.fsck.k9.activity.MessageCompose.attachments " ;
2008-11-01 17:32:06 -04:00
private static final String STATE_KEY_CC_SHOWN =
2009-12-14 21:50:53 -05:00
" com.fsck.k9.activity.MessageCompose.ccShown " ;
2008-11-01 17:32:06 -04:00
private static final String STATE_KEY_BCC_SHOWN =
2009-12-14 21:50:53 -05:00
" com.fsck.k9.activity.MessageCompose.bccShown " ;
2011-05-10 11:54:17 -04:00
private static final String STATE_KEY_QUOTED_TEXT_MODE =
" com.fsck.k9.activity.MessageCompose.QuotedTextShown " ;
2008-11-01 17:32:06 -04:00
private static final String STATE_KEY_SOURCE_MESSAGE_PROCED =
2009-12-14 21:50:53 -05:00
" com.fsck.k9.activity.MessageCompose.stateKeySourceMessageProced " ;
2012-01-21 23:14:58 -05:00
private static final String STATE_KEY_DRAFT_ID = " com.fsck.k9.activity.MessageCompose.draftId " ;
2011-01-12 18:48:28 -05:00
private static final String STATE_KEY_HTML_QUOTE = " com.fsck.k9.activity.MessageCompose.HTMLQuote " ;
2009-06-08 23:11:35 -04:00
private static final String STATE_IDENTITY_CHANGED =
2009-12-14 21:50:53 -05:00
" com.fsck.k9.activity.MessageCompose.identityChanged " ;
2009-06-08 23:11:35 -04:00
private static final String STATE_IDENTITY =
2009-12-14 21:50:53 -05:00
" com.fsck.k9.activity.MessageCompose.identity " ;
2010-08-22 05:51:17 -04:00
private static final String STATE_PGP_DATA = " pgpData " ;
2010-07-02 17:17:06 -04:00
private static final String STATE_IN_REPLY_TO = " com.fsck.k9.activity.MessageCompose.inReplyTo " ;
private static final String STATE_REFERENCES = " com.fsck.k9.activity.MessageCompose.references " ;
2011-08-27 20:42:27 -04:00
private static final String STATE_KEY_READ_RECEIPT = " com.fsck.k9.activity.MessageCompose.messageReadReceipt " ;
2011-11-01 04:02:29 -04:00
private static final String STATE_KEY_DRAFT_NEEDS_SAVING = " com.fsck.k9.activity.MessageCompose.mDraftNeedsSaving " ;
2012-05-20 16:44:32 -04:00
private static final String STATE_KEY_FORCE_PLAIN_TEXT =
" com.fsck.k9.activity.MessageCompose.forcePlainText " ;
private static final String STATE_KEY_QUOTED_TEXT_FORMAT =
" com.fsck.k9.activity.MessageCompose.quotedTextFormat " ;
2013-09-24 21:46:11 -04:00
private static final String STATE_KEY_NUM_ATTACHMENTS_LOADING = " numAttachmentsLoading " ;
private static final String STATE_KEY_WAITING_FOR_ATTACHMENTS = " waitingForAttachments " ;
2008-11-01 17:32:06 -04:00
2013-08-14 12:05:57 -04:00
private static final String LOADER_ARG_ATTACHMENT = " attachment " ;
2013-09-24 21:46:11 -04:00
private static final String FRAGMENT_WAITING_FOR_ATTACHMENT = " waitingForAttachment " ;
2008-11-01 17:32:06 -04:00
private static final int MSG_PROGRESS_ON = 1 ;
private static final int MSG_PROGRESS_OFF = 2 ;
2012-11-20 19:42:19 -05:00
private static final int MSG_SKIPPED_ATTACHMENTS = 3 ;
private static final int MSG_SAVED_DRAFT = 4 ;
private static final int MSG_DISCARDED_DRAFT = 5 ;
2013-09-24 21:46:11 -04:00
private static final int MSG_PERFORM_STALLED_ACTION = 6 ;
2008-11-01 17:32:06 -04:00
private static final int ACTIVITY_REQUEST_PICK_ATTACHMENT = 1 ;
2012-04-08 12:29:08 -04:00
private static final int CONTACT_PICKER_TO = 4 ;
private static final int CONTACT_PICKER_CC = 5 ;
private static final int CONTACT_PICKER_BCC = 6 ;
private static final int CONTACT_PICKER_TO2 = 7 ;
private static final int CONTACT_PICKER_CC2 = 8 ;
private static final int CONTACT_PICKER_BCC2 = 9 ;
2011-03-22 03:06:11 -04:00
2012-03-22 17:17:10 -04:00
private static final Account [ ] EMPTY_ACCOUNT_ARRAY = new Account [ 0 ] ;
2008-11-01 17:32:06 -04:00
2010-08-07 15:25:47 -04:00
/ * *
* Regular expression to remove the first localized " Re: " prefix in subjects .
*
* Currently :
* - " Aw: " ( german : abbreviation for " Antwort " )
* /
2012-01-22 00:25:06 -05:00
private static final Pattern PREFIX = Pattern . compile ( " ^AW[: \\ s] \\ s* " , Pattern . CASE_INSENSITIVE ) ;
2010-08-07 15:25:47 -04:00
2010-07-21 23:15:28 -04:00
/ * *
2010-07-21 23:40:30 -04:00
* The account used for message composition .
2010-07-21 23:15:28 -04:00
* /
2008-11-01 17:32:06 -04:00
private Account mAccount ;
2010-07-21 23:15:28 -04:00
2011-03-22 03:06:11 -04:00
private Contacts mContacts ;
2010-07-21 23:15:28 -04:00
/ * *
* This identity ' s settings are used for message composition .
2010-07-21 23:40:30 -04:00
* Note : This has to be an identity of the account { @link # mAccount } .
2010-07-21 23:15:28 -04:00
* /
2010-03-03 23:00:30 -05:00
private Identity mIdentity ;
2010-07-21 23:15:28 -04:00
2009-06-08 23:11:35 -04:00
private boolean mIdentityChanged = false ;
private boolean mSignatureChanged = false ;
2010-07-21 23:15:28 -04:00
/ * *
* Reference to the source message ( in case of reply , forward , or edit
* draft actions ) .
* /
private MessageReference mMessageReference ;
2008-11-01 17:32:06 -04:00
private Message mSourceMessage ;
2012-05-20 16:44:32 -04:00
/ * *
* " Original " message body
*
* < p >
* The contents of this string will be used instead of the body of a referenced message when
* replying to or forwarding a message . < br >
* Right now this is only used when replying to a signed or encrypted message . It then contains
* the stripped / decrypted body of that message .
* < / p >
* < p > < strong > Note : < / strong >
* When this field is not { @code null } we assume that the message we are composing right now
* should be encrypted .
* < / p >
* /
2010-07-27 08:10:09 -04:00
private String mSourceMessageBody ;
2010-07-21 23:15:28 -04:00
2008-11-01 17:32:06 -04:00
/ * *
* Indicates that the source message has been processed at least once and should not
* be processed on any subsequent loads . This protects us from adding attachments that
* have already been added from the restore of the view state .
* /
private boolean mSourceMessageProcessed = false ;
2013-08-14 12:05:57 -04:00
private int mMaxLoaderId = 0 ;
2008-11-01 17:32:06 -04:00
2012-05-19 21:13:58 -04:00
enum Action {
COMPOSE ,
REPLY ,
REPLY_ALL ,
FORWARD ,
EDIT_DRAFT
}
/ * *
* Contains the action we ' re currently performing ( e . g . replying to a message )
* /
private Action mAction ;
2011-05-10 11:54:17 -04:00
private enum QuotedTextMode {
NONE ,
SHOW ,
HIDE
2013-03-28 14:36:41 -04:00
}
2011-05-10 11:54:17 -04:00
2011-08-27 20:42:27 -04:00
private boolean mReadReceipt = false ;
2011-05-10 11:54:17 -04:00
private QuotedTextMode mQuotedTextMode = QuotedTextMode . NONE ;
2009-06-08 23:11:35 -04:00
2012-05-20 16:44:32 -04:00
/ * *
* Contains the format of the quoted text ( text vs . HTML ) .
* /
private SimpleMessageFormat mQuotedTextFormat ;
/ * *
* When this it { @code true } the message format setting is ignored and we ' re always sending
* a text / plain message .
* /
private boolean mForcePlainText = false ;
2012-03-22 17:17:10 -04:00
private Button mChooseIdentityButton ;
2011-03-22 03:06:11 -04:00
private LinearLayout mCcWrapper ;
private LinearLayout mBccWrapper ;
2008-11-01 17:32:06 -04:00
private MultiAutoCompleteTextView mToView ;
private MultiAutoCompleteTextView mCcView ;
private MultiAutoCompleteTextView mBccView ;
private EditText mSubjectView ;
2013-10-08 19:14:08 -04:00
private EolConvertingEditText mSignatureView ;
private EolConvertingEditText mMessageContentView ;
2008-11-01 17:32:06 -04:00
private LinearLayout mAttachments ;
2011-05-17 11:00:16 -04:00
private Button mQuotedTextShow ;
2008-11-01 17:32:06 -04:00
private View mQuotedTextBar ;
2011-02-05 18:14:02 -05:00
private ImageButton mQuotedTextEdit ;
2008-11-01 17:32:06 -04:00
private ImageButton mQuotedTextDelete ;
2013-10-08 19:14:08 -04:00
private EolConvertingEditText mQuotedText ;
2011-01-12 18:48:28 -05:00
private MessageWebView mQuotedHTML ;
private InsertableHtmlContent mQuotedHtmlContent ; // Container for HTML reply as it's being built.
2010-07-27 08:10:09 -04:00
private View mEncryptLayout ;
private CheckBox mCryptoSignatureCheckbox ;
private CheckBox mEncryptCheckbox ;
private TextView mCryptoSignatureUserId ;
private TextView mCryptoSignatureUserIdRest ;
2011-03-22 03:06:11 -04:00
private ImageButton mAddToFromContacts ;
private ImageButton mAddCcFromContacts ;
private ImageButton mAddBccFromContacts ;
2010-08-22 05:51:17 -04:00
private PgpData mPgpData = null ;
2011-11-19 01:49:04 -05:00
private boolean mAutoEncrypt = false ;
2011-11-21 02:59:51 -05:00
private boolean mContinueWithoutPublicKey = false ;
2009-11-21 17:45:39 -05:00
2009-11-17 16:13:29 -05:00
private String mReferences ;
private String mInReplyTo ;
2012-08-24 11:23:03 -04:00
private Menu mMenu ;
2008-11-01 17:32:06 -04:00
2011-02-05 18:14:02 -05:00
private boolean mSourceProcessed = false ;
2012-05-20 16:44:32 -04:00
enum SimpleMessageFormat {
TEXT ,
HTML
}
/ * *
* The currently used message format .
*
* < p >
* < strong > Note : < / strong >
* Don ' t modify this field directly . Use { @link # updateMessageFormat ( ) } .
* < / p >
* /
private SimpleMessageFormat mMessageFormat ;
2011-11-14 16:16:19 -05:00
private QuoteStyle mQuoteStyle ;
2011-02-05 18:14:02 -05:00
2008-11-01 17:32:06 -04:00
private boolean mDraftNeedsSaving = false ;
2010-07-27 08:10:09 -04:00
private boolean mPreventDraftSaving = false ;
2008-11-01 17:32:06 -04:00
2012-01-22 00:25:06 -05:00
/ * *
* If this is { @code true } we don ' t save the message as a draft in { @link # onPause ( ) } .
* /
private boolean mIgnoreOnPause = false ;
2011-11-03 16:38:53 -04:00
2008-11-01 17:32:06 -04:00
/ * *
2012-01-21 23:14:58 -05:00
* The database ID of this message ' s draft . This is used when saving drafts so the message in
* the database is updated instead of being created anew . This property is INVALID_DRAFT_ID
* until the first save .
2008-11-01 17:32:06 -04:00
* /
2012-01-21 23:14:58 -05:00
private long mDraftId = INVALID_DRAFT_ID ;
2008-11-01 17:32:06 -04:00
2013-09-24 21:46:11 -04:00
/ * *
* Number of attachments currently being fetched .
* /
private int mNumAttachmentsLoading = 0 ;
private enum WaitingAction {
NONE ,
SEND ,
SAVE
}
/ * *
* Specifies what action to perform once attachments have been fetched .
* /
private WaitingAction mWaitingForAttachments = WaitingAction . NONE ;
2011-02-06 17:09:48 -05:00
private Handler mHandler = new Handler ( ) {
2008-11-01 17:32:06 -04:00
@Override
2011-02-06 17:09:48 -05:00
public void handleMessage ( android . os . Message msg ) {
switch ( msg . what ) {
case MSG_PROGRESS_ON :
2012-08-24 12:39:23 -04:00
setSupportProgressBarIndeterminateVisibility ( true ) ;
2011-02-06 17:09:48 -05:00
break ;
case MSG_PROGRESS_OFF :
2012-08-24 12:39:23 -04:00
setSupportProgressBarIndeterminateVisibility ( false ) ;
2011-02-06 17:09:48 -05:00
break ;
case MSG_SKIPPED_ATTACHMENTS :
Toast . makeText (
MessageCompose . this ,
getString ( R . string . message_compose_attachments_skipped_toast ) ,
Toast . LENGTH_LONG ) . show ( ) ;
break ;
case MSG_SAVED_DRAFT :
Toast . makeText (
MessageCompose . this ,
getString ( R . string . message_saved_toast ) ,
Toast . LENGTH_LONG ) . show ( ) ;
break ;
case MSG_DISCARDED_DRAFT :
Toast . makeText (
MessageCompose . this ,
getString ( R . string . message_discarded_toast ) ,
Toast . LENGTH_LONG ) . show ( ) ;
break ;
2013-09-24 21:46:11 -04:00
case MSG_PERFORM_STALLED_ACTION :
performStalledAction ( ) ;
break ;
2011-02-06 17:09:48 -05:00
default :
super . handleMessage ( msg ) ;
break ;
2008-11-01 17:32:06 -04:00
}
}
} ;
private Listener mListener = new Listener ( ) ;
private EmailAddressAdapter mAddressAdapter ;
private Validator mAddressValidator ;
2012-01-11 19:05:01 -05:00
private FontSizes mFontSizes = K9 . getFontSizes ( ) ;
2013-03-28 14:36:41 -04:00
private ContextThemeWrapper mThemeContext ;
2012-01-11 19:05:01 -05:00
2008-11-01 17:32:06 -04:00
/ * *
* Compose a new message using the given account . If account is null the default account
* will be used .
* @param context
* @param account
* /
2011-02-06 17:09:48 -05:00
public static void actionCompose ( Context context , Account account ) {
2012-01-22 00:25:06 -05:00
String accountUuid = ( account = = null ) ?
Preferences . getPreferences ( context ) . getDefaultAccount ( ) . getUuid ( ) :
account . getUuid ( ) ;
2009-11-21 17:45:39 -05:00
Intent i = new Intent ( context , MessageCompose . class ) ;
2012-01-22 00:25:06 -05:00
i . putExtra ( EXTRA_ACCOUNT , accountUuid ) ;
2011-11-14 18:28:45 -05:00
i . setAction ( ACTION_COMPOSE ) ;
2009-11-21 17:45:39 -05:00
context . startActivity ( i ) ;
2008-11-01 17:32:06 -04:00
}
/ * *
2013-01-02 08:07:41 -05:00
* Get intent for composing a new message as a reply to the given message . If replyAll is true
* the function is reply all instead of simply reply .
2008-11-01 17:32:06 -04:00
* @param context
* @param account
* @param message
* @param replyAll
2010-07-27 08:10:09 -04:00
* @param messageBody optional , for decrypted messages , null if it should be grabbed from the given message
2008-11-01 17:32:06 -04:00
* /
2013-01-02 08:07:41 -05:00
public static Intent getActionReplyIntent (
2009-11-21 17:45:39 -05:00
Context context ,
Account account ,
Message message ,
2010-07-27 08:10:09 -04:00
boolean replyAll ,
2011-02-06 17:09:48 -05:00
String messageBody ) {
2008-11-01 17:32:06 -04:00
Intent i = new Intent ( context , MessageCompose . class ) ;
2010-07-27 08:10:09 -04:00
i . putExtra ( EXTRA_MESSAGE_BODY , messageBody ) ;
2010-07-21 23:15:28 -04:00
i . putExtra ( EXTRA_MESSAGE_REFERENCE , message . makeMessageReference ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( replyAll ) {
2008-11-01 17:32:06 -04:00
i . setAction ( ACTION_REPLY_ALL ) ;
2011-02-06 17:09:48 -05:00
} else {
2008-11-01 17:32:06 -04:00
i . setAction ( ACTION_REPLY ) ;
}
2013-01-02 08:07:41 -05:00
return i ;
}
/ * *
* Compose a new message as a reply to the given message . If replyAll is true the function
* is reply all instead of simply reply .
* @param context
* @param account
* @param message
* @param replyAll
* @param messageBody optional , for decrypted messages , null if it should be grabbed from the given message
* /
public static void actionReply (
Context context ,
Account account ,
Message message ,
boolean replyAll ,
String messageBody ) {
context . startActivity ( getActionReplyIntent ( context , account , message , replyAll , messageBody ) ) ;
2008-11-01 17:32:06 -04:00
}
/ * *
* Compose a new message as a forward of the given message .
* @param context
* @param account
* @param message
2010-07-27 08:10:09 -04:00
* @param messageBody optional , for decrypted messages , null if it should be grabbed from the given message
2008-11-01 17:32:06 -04:00
* /
2010-07-27 08:10:09 -04:00
public static void actionForward (
Context context ,
Account account ,
Message message ,
2011-02-06 17:09:48 -05:00
String messageBody ) {
2008-11-01 17:32:06 -04:00
Intent i = new Intent ( context , MessageCompose . class ) ;
2010-07-27 08:10:09 -04:00
i . putExtra ( EXTRA_MESSAGE_BODY , messageBody ) ;
2010-07-21 23:15:28 -04:00
i . putExtra ( EXTRA_MESSAGE_REFERENCE , message . makeMessageReference ( ) ) ;
2008-11-01 17:32:06 -04:00
i . setAction ( ACTION_FORWARD ) ;
context . startActivity ( i ) ;
}
/ * *
* Continue composition of the given message . This action modifies the way this Activity
* handles certain actions .
* Save will attempt to replace the message in the given folder with the updated version .
* Discard will delete the message from the given folder .
* @param context
* @param message
* /
2012-10-05 21:41:32 -04:00
public static void actionEditDraft ( Context context , MessageReference messageReference ) {
2008-11-01 17:32:06 -04:00
Intent i = new Intent ( context , MessageCompose . class ) ;
2012-10-05 21:41:32 -04:00
i . putExtra ( EXTRA_MESSAGE_REFERENCE , messageReference ) ;
2008-11-01 17:32:06 -04:00
i . setAction ( ACTION_EDIT_DRAFT ) ;
context . startActivity ( i ) ;
}
2012-08-24 12:39:23 -04:00
/ *
* This is a workaround for an annoying ( temporarly ? ) issue :
* https : //github.com/JakeWharton/ActionBarSherlock/issues/449
* /
@Override
protected void onPostCreate ( Bundle savedInstanceState ) {
2012-09-13 22:08:17 -04:00
super . onPostCreate ( savedInstanceState ) ;
setSupportProgressBarIndeterminateVisibility ( false ) ;
2012-08-24 12:39:23 -04:00
}
2009-10-17 23:22:17 -04:00
@Override
2011-02-06 17:09:48 -05:00
public void onCreate ( Bundle savedInstanceState ) {
2013-02-06 10:29:48 -05:00
2008-11-01 17:32:06 -04:00
super . onCreate ( savedInstanceState ) ;
2013-01-14 03:07:51 -05:00
if ( UpgradeDatabases . actionUpgradeDatabases ( this , getIntent ( ) ) ) {
finish ( ) ;
return ;
}
2008-11-01 17:32:06 -04:00
requestWindowFeature ( Window . FEATURE_INDETERMINATE_PROGRESS ) ;
2013-02-06 15:43:49 -05:00
if ( K9 . getK9ComposerThemeSetting ( ) ! = K9 . Theme . USE_GLOBAL ) {
// theme the whole content according to the theme (except the action bar)
2013-03-28 14:36:41 -04:00
mThemeContext = new ContextThemeWrapper ( this ,
2013-02-06 15:43:49 -05:00
K9 . getK9ThemeResourceId ( K9 . getK9ComposerTheme ( ) ) ) ;
2013-03-28 14:36:41 -04:00
View v = ( ( LayoutInflater ) mThemeContext . getSystemService ( Context . LAYOUT_INFLATER_SERVICE ) ) .
2013-02-06 15:43:49 -05:00
inflate ( R . layout . message_compose , null ) ;
TypedValue outValue = new TypedValue ( ) ;
// background color needs to be forced
2013-03-28 14:36:41 -04:00
mThemeContext . getTheme ( ) . resolveAttribute ( R . attr . messageViewHeaderBackgroundColor , outValue , true ) ;
2013-02-06 15:43:49 -05:00
v . setBackgroundColor ( outValue . data ) ;
setContentView ( v ) ;
} else {
setContentView ( R . layout . message_compose ) ;
2013-03-31 10:53:27 -04:00
mThemeContext = this ;
2013-02-06 15:43:49 -05:00
}
2008-11-01 17:32:06 -04:00
2010-07-21 23:15:28 -04:00
final Intent intent = getIntent ( ) ;
2011-02-19 13:59:38 -05:00
mMessageReference = intent . getParcelableExtra ( EXTRA_MESSAGE_REFERENCE ) ;
2011-01-18 20:21:27 -05:00
mSourceMessageBody = intent . getStringExtra ( EXTRA_MESSAGE_BODY ) ;
2010-07-21 23:15:28 -04:00
2011-02-06 17:09:48 -05:00
if ( K9 . DEBUG & & mSourceMessageBody ! = null )
2011-01-12 18:48:28 -05:00
Log . d ( K9 . LOG_TAG , " Composing message with explicitly specified message body. " ) ;
2010-07-21 23:15:28 -04:00
final String accountUuid = ( mMessageReference ! = null ) ?
2010-07-21 23:40:30 -04:00
mMessageReference . accountUuid :
intent . getStringExtra ( EXTRA_ACCOUNT ) ;
2010-07-21 23:15:28 -04:00
2010-03-03 23:00:30 -05:00
mAccount = Preferences . getPreferences ( this ) . getAccount ( accountUuid ) ;
2009-12-27 12:22:44 -05:00
2011-02-06 17:09:48 -05:00
if ( mAccount = = null ) {
2009-12-27 12:22:44 -05:00
mAccount = Preferences . getPreferences ( this ) . getDefaultAccount ( ) ;
}
2010-07-21 23:15:28 -04:00
2011-02-06 17:09:48 -05:00
if ( mAccount = = null ) {
2009-12-27 12:22:44 -05:00
/ *
* There are no accounts set up . This should not have happened . Prompt the
* user to set up an account as an acceptable bailout .
* /
startActivity ( new Intent ( this , Accounts . class ) ) ;
mDraftNeedsSaving = false ;
finish ( ) ;
return ;
}
2011-03-22 03:06:11 -04:00
mContacts = Contacts . getInstance ( MessageCompose . this ) ;
2013-03-28 14:36:41 -04:00
mAddressAdapter = new EmailAddressAdapter ( mThemeContext ) ;
2008-11-01 17:32:06 -04:00
mAddressValidator = new EmailAddressValidator ( ) ;
2012-03-22 17:17:10 -04:00
mChooseIdentityButton = ( Button ) findViewById ( R . id . identity ) ;
mChooseIdentityButton . setOnClickListener ( this ) ;
if ( mAccount . getIdentities ( ) . size ( ) = = 1 & &
Preferences . getPreferences ( this ) . getAvailableAccounts ( ) . size ( ) = = 1 ) {
2012-03-24 17:51:33 -04:00
mChooseIdentityButton . setVisibility ( View . GONE ) ;
2012-03-22 17:17:10 -04:00
}
2011-03-22 03:06:11 -04:00
mToView = ( MultiAutoCompleteTextView ) findViewById ( R . id . to ) ;
mCcView = ( MultiAutoCompleteTextView ) findViewById ( R . id . cc ) ;
mBccView = ( MultiAutoCompleteTextView ) findViewById ( R . id . bcc ) ;
mSubjectView = ( EditText ) findViewById ( R . id . subject ) ;
2010-12-23 04:58:13 -05:00
mSubjectView . getInputExtras ( true ) . putBoolean ( " allowEmoji " , true ) ;
2009-11-21 17:45:39 -05:00
2011-03-22 03:06:11 -04:00
mAddToFromContacts = ( ImageButton ) findViewById ( R . id . add_to ) ;
mAddCcFromContacts = ( ImageButton ) findViewById ( R . id . add_cc ) ;
mAddBccFromContacts = ( ImageButton ) findViewById ( R . id . add_bcc ) ;
mCcWrapper = ( LinearLayout ) findViewById ( R . id . cc_wrapper ) ;
mBccWrapper = ( LinearLayout ) findViewById ( R . id . bcc_wrapper ) ;
2012-08-09 21:38:10 -04:00
if ( mAccount . isAlwaysShowCcBcc ( ) ) {
onAddCcBcc ( ) ;
}
2013-10-08 19:14:08 -04:00
EolConvertingEditText upperSignature = ( EolConvertingEditText ) findViewById ( R . id . upper_signature ) ;
EolConvertingEditText lowerSignature = ( EolConvertingEditText ) findViewById ( R . id . lower_signature ) ;
2009-11-21 17:45:39 -05:00
2013-10-08 19:14:08 -04:00
mMessageContentView = ( EolConvertingEditText ) findViewById ( R . id . message_content ) ;
2011-01-04 08:25:59 -05:00
mMessageContentView . getInputExtras ( true ) . putBoolean ( " allowEmoji " , true ) ;
2013-02-06 10:29:48 -05:00
2008-11-01 17:32:06 -04:00
mAttachments = ( LinearLayout ) findViewById ( R . id . attachments ) ;
2011-05-17 11:00:16 -04:00
mQuotedTextShow = ( Button ) findViewById ( R . id . quoted_text_show ) ;
2008-11-01 17:32:06 -04:00
mQuotedTextBar = findViewById ( R . id . quoted_text_bar ) ;
2011-02-05 18:14:02 -05:00
mQuotedTextEdit = ( ImageButton ) findViewById ( R . id . quoted_text_edit ) ;
2008-11-01 17:32:06 -04:00
mQuotedTextDelete = ( ImageButton ) findViewById ( R . id . quoted_text_delete ) ;
2013-10-08 19:14:08 -04:00
mQuotedText = ( EolConvertingEditText ) findViewById ( R . id . quoted_text ) ;
2011-01-04 08:25:59 -05:00
mQuotedText . getInputExtras ( true ) . putBoolean ( " allowEmoji " , true ) ;
2008-11-01 17:32:06 -04:00
2011-01-12 18:48:28 -05:00
mQuotedHTML = ( MessageWebView ) findViewById ( R . id . quoted_html ) ;
mQuotedHTML . configure ( ) ;
// Disable the ability to click links in the quoted HTML page. I think this is a nice feature, but if someone
// feels this should be a preference (or should go away all together), I'm ok with that too. -achen 20101130
2011-02-06 17:09:48 -05:00
mQuotedHTML . setWebViewClient ( new WebViewClient ( ) {
2011-01-12 18:48:28 -05:00
@Override
2011-02-06 17:09:48 -05:00
public boolean shouldOverrideUrlLoading ( WebView view , String url ) {
2011-01-12 18:48:28 -05:00
return true ;
}
} ) ;
2011-02-06 17:09:48 -05:00
TextWatcher watcher = new TextWatcher ( ) {
2012-01-22 00:25:06 -05:00
@Override
public void beforeTextChanged ( CharSequence s , int start , int before , int after ) {
/* do nothing */
}
2008-11-01 17:32:06 -04:00
2012-01-22 00:25:06 -05:00
@Override
public void onTextChanged ( CharSequence s , int start , int before , int count ) {
2008-11-01 17:32:06 -04:00
mDraftNeedsSaving = true ;
}
2012-01-22 00:25:06 -05:00
@Override
public void afterTextChanged ( android . text . Editable s ) { /* do nothing */ }
2008-11-01 17:32:06 -04:00
} ;
2011-11-21 02:59:51 -05:00
// For watching changes to the To:, Cc:, and Bcc: fields for auto-encryption on a matching
// address.
2011-11-19 01:49:04 -05:00
TextWatcher recipientWatcher = new TextWatcher ( ) {
2012-01-22 00:25:06 -05:00
@Override
public void beforeTextChanged ( CharSequence s , int start , int before , int after ) {
/* do nothing */
}
2011-11-19 01:49:04 -05:00
2012-01-22 00:25:06 -05:00
@Override
2011-11-19 01:49:04 -05:00
public void onTextChanged ( CharSequence s , int start , int before , int count ) {
mDraftNeedsSaving = true ;
}
2012-01-22 00:25:06 -05:00
@Override
2011-11-19 01:49:04 -05:00
public void afterTextChanged ( android . text . Editable s ) {
final CryptoProvider crypto = mAccount . getCryptoProvider ( ) ;
if ( mAutoEncrypt & & crypto . isAvailable ( getApplicationContext ( ) ) ) {
for ( Address address : getRecipientAddresses ( ) ) {
2011-11-21 02:59:51 -05:00
if ( crypto . hasPublicKeyForEmail ( getApplicationContext ( ) ,
address . getAddress ( ) ) ) {
2011-11-19 01:49:04 -05:00
mEncryptCheckbox . setChecked ( true ) ;
2011-11-21 02:59:51 -05:00
mContinueWithoutPublicKey = false ;
2011-11-19 01:49:04 -05:00
break ;
}
}
}
}
} ;
2011-02-06 17:09:48 -05:00
TextWatcher sigwatcher = new TextWatcher ( ) {
2012-01-22 00:25:06 -05:00
@Override
public void beforeTextChanged ( CharSequence s , int start , int before , int after ) {
/* do nothing */
}
2009-06-08 23:11:35 -04:00
2012-01-22 00:25:06 -05:00
@Override
public void onTextChanged ( CharSequence s , int start , int before , int count ) {
2009-06-08 23:11:35 -04:00
mDraftNeedsSaving = true ;
mSignatureChanged = true ;
}
2012-01-22 00:25:06 -05:00
@Override
public void afterTextChanged ( android . text . Editable s ) { /* do nothing */ }
2009-06-08 23:11:35 -04:00
} ;
2011-11-19 01:49:04 -05:00
mToView . addTextChangedListener ( recipientWatcher ) ;
mCcView . addTextChangedListener ( recipientWatcher ) ;
mBccView . addTextChangedListener ( recipientWatcher ) ;
2008-11-01 17:32:06 -04:00
mSubjectView . addTextChangedListener ( watcher ) ;
2009-11-21 17:45:39 -05:00
2008-11-01 17:32:06 -04:00
mMessageContentView . addTextChangedListener ( watcher ) ;
2009-11-10 19:45:19 -05:00
mQuotedText . addTextChangedListener ( watcher ) ;
2008-11-01 17:32:06 -04:00
2011-03-22 03:06:11 -04:00
/* Yes, there really are poeple who ship versions of android without a contact picker */
if ( mContacts . hasContactPicker ( ) ) {
mAddToFromContacts . setOnClickListener ( new OnClickListener ( ) {
@Override public void onClick ( View v ) {
doLaunchContactPicker ( CONTACT_PICKER_TO ) ;
}
} ) ;
mAddCcFromContacts . setOnClickListener ( new OnClickListener ( ) {
@Override public void onClick ( View v ) {
doLaunchContactPicker ( CONTACT_PICKER_CC ) ;
}
} ) ;
mAddBccFromContacts . setOnClickListener ( new OnClickListener ( ) {
@Override public void onClick ( View v ) {
doLaunchContactPicker ( CONTACT_PICKER_BCC ) ;
}
} ) ;
} else {
mAddToFromContacts . setVisibility ( View . GONE ) ;
mAddCcFromContacts . setVisibility ( View . GONE ) ;
mAddBccFromContacts . setVisibility ( View . GONE ) ;
}
2008-11-01 17:32:06 -04:00
/ *
* We set this to invisible by default . Other methods will turn it back on if it ' s
* needed .
* /
2011-05-10 11:54:17 -04:00
showOrHideQuotedText ( QuotedTextMode . NONE ) ;
mQuotedTextShow . setOnClickListener ( this ) ;
2011-02-05 18:14:02 -05:00
mQuotedTextEdit . setOnClickListener ( this ) ;
2008-11-01 17:32:06 -04:00
mQuotedTextDelete . setOnClickListener ( this ) ;
mToView . setAdapter ( mAddressAdapter ) ;
mToView . setTokenizer ( new Rfc822Tokenizer ( ) ) ;
mToView . setValidator ( mAddressValidator ) ;
mCcView . setAdapter ( mAddressAdapter ) ;
mCcView . setTokenizer ( new Rfc822Tokenizer ( ) ) ;
mCcView . setValidator ( mAddressValidator ) ;
mBccView . setAdapter ( mAddressAdapter ) ;
mBccView . setTokenizer ( new Rfc822Tokenizer ( ) ) ;
mBccView . setValidator ( mAddressValidator ) ;
2011-02-06 17:09:48 -05:00
if ( savedInstanceState ! = null ) {
2008-11-01 17:32:06 -04:00
/ *
2010-12-24 19:27:09 -05:00
* This data gets used in onCreate , so grab it here instead of onRestoreInstanceState
2008-11-01 17:32:06 -04:00
* /
r62972@17h: jesse | 2009-05-07 10:49:32 -0400
First stab at a folderlist that doesn't know or care about messages
r62973@17h: jesse | 2009-05-07 10:50:11 -0400
A very broken first stab at a message list that only knows about one folder.
r62974@17h: jesse | 2009-05-07 10:50:44 -0400
When you go from an account list to an individual account, open a folderlist, not an fml
r62975@17h: jesse | 2009-05-07 10:51:24 -0400
Update Welcome activity to open an ml instead of an fml
r62976@17h: jesse | 2009-05-07 10:51:59 -0400
When setting up accounts is over, open an fl instead of an fml
r62977@17h: jesse | 2009-05-07 10:52:51 -0400
Update MessageView to use folderinfoholders and messageinfoholders from the 'correct' classes.
r62978@17h: jesse | 2009-05-07 10:59:07 -0400
MailService now notifies the fl instead of the fml. Not sure if it should also notify the ml. - will require testing
r62979@17h: jesse | 2009-05-07 11:01:09 -0400
Switch MessagingController's notifications from notifying the FML to notifying an ML
r62980@17h: jesse | 2009-05-07 11:25:22 -0400
Update AndroidManifest to know about the new world order
r62981@17h: jesse | 2009-05-07 11:26:11 -0400
Try to follow the android sdk docs for intent creation
r62982@17h: jesse | 2009-05-07 11:28:30 -0400
reset MessageList for another try at the conversion
r62983@17h: jesse | 2009-05-07 11:47:33 -0400
This version doesn't crash and has a working 'folder' layer. now to clean up the message list layer
r62984@17h: jesse | 2009-05-07 15:18:04 -0400
move step 1
r62985@17h: jesse | 2009-05-07 15:18:37 -0400
move step 1
r62986@17h: jesse | 2009-05-07 15:22:47 -0400
rename step 1
r62987@17h: jesse | 2009-05-07 17:38:02 -0400
checkpoint to move
r62988@17h: jesse | 2009-05-07 17:40:01 -0400
checkpointing a state with a working folder list and a message list that doesn't explode
r62989@17h: jesse | 2009-05-07 17:40:26 -0400
Remove debugging cruft from Welcome
r62990@17h: jesse | 2009-05-07 22:00:12 -0400
Basic functionality works.
r62991@17h: jesse | 2009-05-08 04:19:52 -0400
added a tool to build a K-9 "Beta"
r62992@17h: jesse | 2009-05-08 04:20:03 -0400
remove a disused file
r62993@17h: jesse | 2009-05-09 06:07:02 -0400
upgrading build infrastructure for the 1.5 sdk
r62994@17h: jesse | 2009-05-09 06:22:02 -0400
further refine onOpenMessage, removing more folder assumptions
r62995@17h: jesse | 2009-05-09 20:07:20 -0400
Make the Welcome activity open the autoexpandfolder rather than INBOX
r62996@17h: jesse | 2009-05-09 20:14:10 -0400
MessageList now stores the Folder name it was working with across pause-reload
r62997@17h: jesse | 2009-05-09 20:14:26 -0400
Removing dead code from FolderList
r63060@17h: jesse | 2009-05-10 00:07:33 -0400
Replace the old message list refreshing code which cleared and rebuilt the list from scratch with code which updates or deletes existing messages.
Add "go back to folder list" code
r63061@17h: jesse | 2009-05-10 00:07:50 -0400
fix message list menus for new world order
r63062@17h: jesse | 2009-05-10 00:08:11 -0400
Remove message list options from folder list menus
r63063@17h: jesse | 2009-05-10 00:10:02 -0400
remove more message list options from the folder list
r63064@17h: jesse | 2009-05-10 00:10:19 -0400
fix build.xml for the new android world order
r63065@17h: jesse | 2009-05-10 00:39:23 -0400
reformatted in advance of bug tracing
r63066@17h: jesse | 2009-05-10 05:53:28 -0400
fix our 'close' behavior to not leave extra activities around
clean up more vestigal code
r63067@17h: jesse | 2009-05-10 18:44:25 -0400
Improve "back button / accounts" workflow from FolderList -> AccountList
r63068@17h: jesse | 2009-05-10 19:11:47 -0400
* Add required code for the 'k9beta' build
r63069@17h: jesse | 2009-05-10 19:12:05 -0400
Make the folder list white backgrounded.
r63070@17h: jesse | 2009-05-10 19:12:26 -0400
* Include our required libraries in build.xml
r63071@17h: jesse | 2009-05-10 19:13:07 -0400
Added directories for our built code and our generated code
r63072@17h: jesse | 2009-05-10 19:13:36 -0400
Added a "back" button image
r63073@17h: jesse | 2009-05-10 20:13:50 -0400
Switch next/prev buttons to triangles for I18N and eventual "more easy-to-hit buttons" win
r63074@17h: jesse | 2009-05-10 20:17:18 -0400
Tidy Accounts.java for some perf hacking.
r63081@17h: jesse | 2009-05-10 22:13:33 -0400
First pass reformatting of the MessagingController
r63082@17h: jesse | 2009-05-10 23:50:28 -0400
MessageList now correctly updates when a background sync happens
r63083@17h: jesse | 2009-05-10 23:50:53 -0400
Tidying FolderList
r63084@17h: jesse | 2009-05-10 23:51:09 -0400
tidy
r63085@17h: jesse | 2009-05-10 23:51:27 -0400
tidy
r63086@17h: jesse | 2009-05-11 00:17:06 -0400
Properly update unread counts in the FolderList after sync
r63087@17h: jesse | 2009-05-11 01:38:14 -0400
Minor refactoring for readability. replace a boolean with a constant.
r63090@17h: jesse | 2009-05-11 02:58:31 -0400
now that the foreground of message lists is light, we don't need the light messagebox
r63091@17h: jesse | 2009-05-11 17:15:02 -0400
Added a string for "back to folder list"
r63092@17h: jesse | 2009-05-11 17:15:24 -0400
Added a message list header with a back button
r63093@17h: jesse | 2009-05-11 17:15:54 -0400
Remove the "folder list" button from the options menu. no sense duplicating it
r63094@17h: jesse | 2009-05-11 17:17:06 -0400
Refactored views, adding our replacement scrollable header
r63184@17h: jesse | 2009-05-12 07:07:15 -0400
fix weird bug where message lists could show a header element for a child
r63185@17h: jesse | 2009-05-12 07:08:12 -0400
Add new-style headers to folder lists. reimplement "get folder by name" to not use a bloody for loop
r63211@17h: jesse | 2009-05-12 18:37:48 -0400
Restore the former glory of the "load more messages" widget. it still needs an overhaul
r63296@17h: jesse | 2009-05-12 23:23:21 -0400
Get the indeterminate progress bar to show up again when you click "get more messages"
r63297@17h: jesse | 2009-05-13 02:40:39 -0400
Fixed off-by-one errors in click and keybindings for messagelist
r63298@17h: jesse | 2009-05-13 06:04:01 -0400
Put the folder title in the name of the folderSettings popup
r63299@17h: jesse | 2009-05-13 06:04:49 -0400
Reformatting. Removing debug logging
r63300@17h: jesse | 2009-05-13 06:05:32 -0400
Fixing "wrong item selected" bugs in the FolderList
r63328@17h: jesse | 2009-05-13 13:20:00 -0400
Update MessageView for 1.5
r63329@17h: jesse | 2009-05-13 13:50:29 -0400
A couple fixes to "picking the right item"
Titles on the message context menu
r63330@17h: jesse | 2009-05-13 13:58:37 -0400
Added an "open" context menu item to the folder list
r63347@17h: jesse | 2009-05-13 18:00:02 -0400
Try to get folderlists to sort in a stable way, so they jump around less in the ui
r63349@17h: jesse | 2009-05-13 20:37:19 -0400
Switch to using non-message-passing based notifications for redisplay of message lists, cut down redisplay frequency to not overload the display
r63432@17h: jesse | 2009-05-16 13:38:49 -0400
Android 1.5 no longer gives us apache.commons.codec by default and apache.commons.logging by default. Import them so we have em.
There's probably something smarter to do here.
r63438@17h: jesse | 2009-05-16 14:12:06 -0400
removed dead code
r63439@17h: jesse | 2009-05-16 14:30:57 -0400
Minor tidy
r63440@17h: jesse | 2009-05-16 14:39:34 -0400
First pass implementation making MessageList streamy for faster startup
r63441@17h: jesse | 2009-05-16 21:57:41 -0400
There's no reason for the FolderList to list local messages
r63442@17h: jesse | 2009-05-16 21:58:57 -0400
Switch to actually refreshing the message list after each item is loaded
r63450@17h: jesse | 2009-05-16 22:34:18 -0400
Default to pulling items out of the LocalStore by date, descending. (since that's the uneditable default ordering)
This makes our messages come out of the store in the order the user should see them
r63451@17h: jesse | 2009-05-16 22:34:44 -0400
Set some new defaults for the FolderList
r63452@17h: jesse | 2009-05-16 22:35:43 -0400
set some new message list item defaults
r63456@17h: jesse | 2009-05-17 12:56:10 -0400
It's not clear that Pop and WebDav actually set us an InternalDate. I'd rather use that so that spam doesn't topsort. But I also want this to _work_
r63457@17h: jesse | 2009-05-17 12:56:47 -0400
actually check to make sure we have a message to remove before removing it.
r63458@17h: jesse | 2009-05-17 13:10:07 -0400
Flip "security type" to before the port number, since changing security type is the thing more users are likely to know/care about and resets port number
r63469@17h: jesse | 2009-05-17 18:42:39 -0400
Provisional fix for "see the FoldeRList twice" bug
r63471@17h: jesse | 2009-05-17 20:47:41 -0400
Remove title bar from the message view
r63544@17h: jesse | 2009-05-20 23:53:38 -0400
folderlist tidying before i dig into the jumpy ordering bug
r63545@17h: jesse | 2009-05-20 23:56:00 -0400
Killing dead variables
r63546@17h: jesse | 2009-05-21 00:58:36 -0400
make the whole title section clicky
r63556@17h: jesse | 2009-05-21 01:48:13 -0400
Fix where we go when someone deletes a message
r63558@17h: jesse | 2009-05-21 22:44:46 -0400
Working toward switchable themes
r63563@17h: jesse | 2009-05-21 23:53:09 -0400
Make the MessageList's colors actually just inherit from the theme, rather than hardcoding black
r63567@17h: jesse | 2009-05-22 10:14:13 -0400
Kill a now-redundant comment
r63571@17h: jesse | 2009-05-22 19:43:30 -0400
further theme-independence work
r63572@17h: jesse | 2009-05-22 19:55:23 -0400
gete -> get (typo fix)
r63573@17h: jesse | 2009-05-22 22:48:49 -0400
First cut of a global prefs system as well as a theme preference. not that it works yet
r63577@17h: jesse | 2009-05-24 14:49:52 -0400
Once a user has actually put in valid user credentials, start syncing mail and folders in the background instantly.
This gives us a much better "new startup" experience
r63578@17h: jesse | 2009-05-24 14:55:00 -0400
MessageList doesn't need FolderUpdateWorker
r63579@17h: jesse | 2009-05-24 17:57:15 -0400
Fix "get message by uid"
Switch to showing messages 10 by 10, rather than 1 by 1 for huge loadtime performance improvements
r63587@17h: jesse | 2009-05-24 19:19:56 -0400
Cut down LocalMessage creation to not generate a MessageId or date formatter.
r63589@17h: jesse | 2009-05-24 22:22:32 -0400
Switch to null-escaping email address boundaries, rather than a VERY expensive URL-encoding
r63590@17h: jesse | 2009-05-24 22:23:21 -0400
Clean up our "auto-refresh the list when adding messages after a sync"
r63593@17h: jesse | 2009-05-24 22:53:45 -0400
replace isDateToday with a "rolling 18 hour window" variant that's more likely to give the user a useful answer and is 30x faster.
r63595@17h: jesse | 2009-05-24 23:54:14 -0400
When instantiating messges from the LocalStore, there's no need to clear headers before setting them, nor is there a need to set a generated message id
r63596@17h: jesse | 2009-05-24 23:54:39 -0400
make an overridable setGeneratedMessageId
r63597@17h: jesse | 2009-05-24 23:54:55 -0400
Remove new lies from comments
r63598@17h: jesse | 2009-05-24 23:55:35 -0400
Replace insanely expensive message header "name" part quoting with something consistent and cheap that does its work on the way INTO the database
r63605@17h: jesse | 2009-05-25 17:28:24 -0400
bring back the 1.1 sdk build.xml
r63606@17h: jesse | 2009-05-25 22:32:11 -0400
Actually enable switchable themese and compilation on 1.1
r63692@17h: jesse | 2009-05-29 23:55:17 -0400
Switch back to having titles for folder and message lists.
Restore auto-open-folder functionality
r63694@17h: jesse | 2009-05-30 18:50:39 -0400
Remove several off-by-one errors introduced by yesterday's return to android titlebars
r63696@17h: jesse | 2009-05-30 23:45:03 -0400
use convertView properly for performance and memory imrpovement in FolderList and MessageList
r63698@17h: jesse | 2009-05-31 19:42:59 -0400
Switch to using background shading to indicate "not yet fetched"
r63701@17h: jesse | 2009-05-31 21:28:47 -0400
Remving code we don't actually need these bits of apache commons on 1.1
2009-05-31 21:35:05 -04:00
mSourceMessageProcessed = savedInstanceState . getBoolean ( STATE_KEY_SOURCE_MESSAGE_PROCED , false ) ;
2008-11-01 17:32:06 -04:00
}
2012-05-19 21:13:58 -04:00
if ( initFromIntent ( intent ) ) {
mAction = Action . COMPOSE ;
2013-10-09 15:53:39 -04:00
mDraftNeedsSaving = true ;
2012-05-19 21:13:58 -04:00
} else {
String action = intent . getAction ( ) ;
if ( ACTION_COMPOSE . equals ( action ) ) {
mAction = Action . COMPOSE ;
} else if ( ACTION_REPLY . equals ( action ) ) {
mAction = Action . REPLY ;
} else if ( ACTION_REPLY_ALL . equals ( action ) ) {
mAction = Action . REPLY_ALL ;
} else if ( ACTION_FORWARD . equals ( action ) ) {
mAction = Action . FORWARD ;
} else if ( ACTION_EDIT_DRAFT . equals ( action ) ) {
mAction = Action . EDIT_DRAFT ;
} else {
// This shouldn't happen
Log . w ( K9 . LOG_TAG , " MessageCompose was started with an unsupported action " ) ;
mAction = Action . COMPOSE ;
}
}
2009-11-21 17:45:39 -05:00
2011-02-06 17:09:48 -05:00
if ( mIdentity = = null ) {
2009-11-21 17:45:39 -05:00
mIdentity = mAccount . getIdentity ( 0 ) ;
2009-06-08 23:11:35 -04:00
}
2009-11-21 17:45:39 -05:00
2011-02-06 17:09:48 -05:00
if ( mAccount . isSignatureBeforeQuotedText ( ) ) {
2009-06-08 23:11:35 -04:00
mSignatureView = upperSignature ;
lowerSignature . setVisibility ( View . GONE ) ;
2011-02-06 17:09:48 -05:00
} else {
2009-06-08 23:11:35 -04:00
mSignatureView = lowerSignature ;
upperSignature . setVisibility ( View . GONE ) ;
}
mSignatureView . addTextChangedListener ( sigwatcher ) ;
2009-11-21 17:45:39 -05:00
2011-02-06 17:09:48 -05:00
if ( ! mIdentity . getSignatureUse ( ) ) {
2010-02-08 12:47:00 -05:00
mSignatureView . setVisibility ( View . GONE ) ;
}
2011-08-27 20:42:27 -04:00
mReadReceipt = mAccount . isMessageReadReceiptAlways ( ) ;
2011-11-14 16:16:19 -05:00
mQuoteStyle = mAccount . getQuoteStyle ( ) ;
2011-02-05 18:14:02 -05:00
2012-03-22 17:17:10 -04:00
updateFrom ( ) ;
2011-02-06 17:09:48 -05:00
if ( ! mSourceMessageProcessed ) {
2009-11-16 15:47:27 -05:00
updateSignature ( ) ;
2009-05-13 20:03:19 -04:00
2012-05-19 21:13:58 -04:00
if ( mAction = = Action . REPLY | | mAction = = Action . REPLY_ALL | |
mAction = = Action . FORWARD | | mAction = = Action . EDIT_DRAFT ) {
2009-11-16 15:47:27 -05:00
/ *
* If we need to load the message we add ourself as a message listener here
* so we can kick it off . Normally we add in onResume but we don ' t
* want to reload the message every time the activity is resumed .
* There is no harm in adding twice .
* /
MessagingController . getInstance ( getApplication ( ) ) . addListener ( mListener ) ;
2010-07-21 23:15:28 -04:00
final Account account = Preferences . getPreferences ( this ) . getAccount ( mMessageReference . accountUuid ) ;
final String folderName = mMessageReference . folderName ;
final String sourceMessageUid = mMessageReference . uid ;
MessagingController . getInstance ( getApplication ( ) ) . loadMessageForView ( account , folderName , sourceMessageUid , null ) ;
2009-10-17 23:22:17 -04:00
}
2009-10-21 20:41:06 -04:00
2012-05-19 21:13:58 -04:00
if ( mAction ! = Action . EDIT_DRAFT ) {
2012-02-18 10:26:28 -05:00
addAddresses ( mBccView , mAccount . getAlwaysBcc ( ) ) ;
2009-11-16 15:47:27 -05:00
}
}
2009-09-16 23:43:02 -04:00
2012-05-19 21:13:58 -04:00
if ( mAction = = Action . REPLY | | mAction = = Action . REPLY_ALL ) {
2011-02-03 01:32:29 -05:00
mMessageReference . flag = Flag . ANSWERED ;
}
2012-05-19 21:13:58 -04:00
if ( mAction = = Action . REPLY | | mAction = = Action . REPLY_ALL | |
mAction = = Action . EDIT_DRAFT ) {
2009-10-17 23:22:17 -04:00
//change focus to message body.
mMessageContentView . requestFocus ( ) ;
2011-02-14 02:28:03 -05:00
} else {
// Explicitly set focus to "To:" input field (see issue 2998)
mToView . requestFocus ( ) ;
2009-10-17 23:22:17 -04:00
}
2009-11-16 15:47:27 -05:00
2012-08-20 22:09:34 -04:00
if ( mAction = = Action . FORWARD ) {
mMessageReference . flag = Flag . FORWARDED ;
}
2011-02-14 02:28:03 -05:00
2011-01-18 20:21:27 -05:00
mEncryptLayout = findViewById ( R . id . layout_encrypt ) ;
2010-07-27 08:10:09 -04:00
mCryptoSignatureCheckbox = ( CheckBox ) findViewById ( R . id . cb_crypto_signature ) ;
mCryptoSignatureUserId = ( TextView ) findViewById ( R . id . userId ) ;
mCryptoSignatureUserIdRest = ( TextView ) findViewById ( R . id . userIdRest ) ;
mEncryptCheckbox = ( CheckBox ) findViewById ( R . id . cb_encrypt ) ;
2012-05-20 16:44:32 -04:00
mEncryptCheckbox . setOnCheckedChangeListener ( new OnCheckedChangeListener ( ) {
@Override
public void onCheckedChanged ( CompoundButton buttonView , boolean isChecked ) {
updateMessageFormat ( ) ;
}
} ) ;
2011-11-19 01:49:04 -05:00
if ( mSourceMessageBody ! = null ) {
// mSourceMessageBody is set to something when replying to and forwarding decrypted
// messages, so the sender probably wants the message to be encrypted.
mEncryptCheckbox . setChecked ( true ) ;
}
2010-07-27 08:10:09 -04:00
initializeCrypto ( ) ;
2010-08-22 05:51:17 -04:00
final CryptoProvider crypto = mAccount . getCryptoProvider ( ) ;
2011-02-06 17:09:48 -05:00
if ( crypto . isAvailable ( this ) ) {
2010-07-27 08:10:09 -04:00
mEncryptLayout . setVisibility ( View . VISIBLE ) ;
2011-02-06 17:09:48 -05:00
mCryptoSignatureCheckbox . setOnClickListener ( new OnClickListener ( ) {
2010-07-27 08:10:09 -04:00
@Override
2011-02-06 17:09:48 -05:00
public void onClick ( View v ) {
2010-07-27 08:10:09 -04:00
CheckBox checkBox = ( CheckBox ) v ;
2011-02-06 17:09:48 -05:00
if ( checkBox . isChecked ( ) ) {
2010-07-27 08:10:09 -04:00
mPreventDraftSaving = true ;
2011-02-06 17:09:48 -05:00
if ( ! crypto . selectSecretKey ( MessageCompose . this , mPgpData ) ) {
2010-07-27 08:10:09 -04:00
mPreventDraftSaving = false ;
}
checkBox . setChecked ( false ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-08-22 05:51:17 -04:00
mPgpData . setSignatureKeyId ( 0 ) ;
2010-07-27 08:10:09 -04:00
updateEncryptLayout ( ) ;
}
}
} ) ;
2011-02-06 17:09:48 -05:00
if ( mAccount . getCryptoAutoSignature ( ) ) {
2010-08-22 05:51:17 -04:00
long ids [ ] = crypto . getSecretKeyIdsFromEmail ( this , mIdentity . getEmail ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( ids ! = null & & ids . length > 0 ) {
2010-08-22 05:51:17 -04:00
mPgpData . setSignatureKeyId ( ids [ 0 ] ) ;
mPgpData . setSignatureUserId ( crypto . getUserId ( this , ids [ 0 ] ) ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-08-22 05:51:17 -04:00
mPgpData . setSignatureKeyId ( 0 ) ;
mPgpData . setSignatureUserId ( null ) ;
2010-07-27 08:10:09 -04:00
}
}
updateEncryptLayout ( ) ;
2011-11-19 01:49:04 -05:00
mAutoEncrypt = mAccount . isCryptoAutoEncrypt ( ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-07-27 08:10:09 -04:00
mEncryptLayout . setVisibility ( View . GONE ) ;
}
2012-01-11 19:05:01 -05:00
// Set font size of input controls
int fontSize = mFontSizes . getMessageComposeInput ( ) ;
2013-02-08 21:19:22 -05:00
mFontSizes . setViewTextSize ( mToView , fontSize ) ;
mFontSizes . setViewTextSize ( mCcView , fontSize ) ;
mFontSizes . setViewTextSize ( mBccView , fontSize ) ;
mFontSizes . setViewTextSize ( mSubjectView , fontSize ) ;
mFontSizes . setViewTextSize ( mMessageContentView , fontSize ) ;
mFontSizes . setViewTextSize ( mQuotedText , fontSize ) ;
mFontSizes . setViewTextSize ( mSignatureView , fontSize ) ;
2012-05-20 16:44:32 -04:00
updateMessageFormat ( ) ;
2012-11-20 19:42:19 -05:00
setTitle ( ) ;
2008-11-01 17:32:06 -04:00
}
2010-11-13 21:27:42 -05:00
/ * *
* Handle external intents that trigger the message compose activity .
*
2012-05-19 21:13:58 -04:00
* < p >
* Supported external intents :
* < ul >
* < li > { @link Intent # ACTION_VIEW } < / li >
* < li > { @link Intent # ACTION_SENDTO } < / li >
* < li > { @link Intent # ACTION_SEND } < / li >
* < li > { @link Intent # ACTION_SEND_MULTIPLE } < / li >
* < / ul >
* < / p >
*
* @param intent
* The ( external ) intent that started the activity .
*
* @return { @code true } , if this activity was started by an external intent . { @code false } ,
* otherwise .
2010-11-13 21:27:42 -05:00
* /
2012-05-19 21:13:58 -04:00
private boolean initFromIntent ( final Intent intent ) {
boolean startedByExternalIntent = false ;
2010-11-13 21:27:42 -05:00
final String action = intent . getAction ( ) ;
2011-02-06 17:09:48 -05:00
if ( Intent . ACTION_VIEW . equals ( action ) | | Intent . ACTION_SENDTO . equals ( action ) ) {
2010-11-13 21:27:42 -05:00
/ *
* Someone has clicked a mailto : link . The address is in the URI .
* /
2011-02-06 17:09:48 -05:00
if ( intent . getData ( ) ! = null ) {
2010-11-13 21:27:42 -05:00
Uri uri = intent . getData ( ) ;
2011-02-06 17:09:48 -05:00
if ( " mailto " . equals ( uri . getScheme ( ) ) ) {
2010-11-13 21:27:42 -05:00
initializeFromMailto ( uri ) ;
}
}
/ *
2014-01-29 20:47:10 -05:00
* Note : According to the documentation ACTION_VIEW and ACTION_SENDTO don ' t accept
2012-05-06 11:47:59 -04:00
* EXTRA_ * parameters .
* And previously we didn ' t process these EXTRAs . But it looks like nobody bothers to
* read the official documentation and just copies wrong sample code that happens to
* work with the AOSP Email application . And because even big players get this wrong ,
2014-01-29 20:47:10 -05:00
* we ' re now finally giving in and read the EXTRAs for those actions ( below ) .
2010-11-13 21:27:42 -05:00
* /
}
2012-05-06 11:47:59 -04:00
if ( Intent . ACTION_SEND . equals ( action ) | | Intent . ACTION_SEND_MULTIPLE . equals ( action ) | |
2014-01-29 20:47:10 -05:00
Intent . ACTION_SENDTO . equals ( action ) | | Intent . ACTION_VIEW . equals ( action ) ) {
2012-05-19 21:13:58 -04:00
startedByExternalIntent = true ;
2012-05-06 11:47:59 -04:00
2010-11-13 21:27:42 -05:00
/ *
2014-01-29 20:47:10 -05:00
* Note : Here we allow a slight deviation from the documented behavior .
2010-11-13 21:27:42 -05:00
* EXTRA_TEXT is used as message body ( if available ) regardless of the MIME
* type of the intent . In addition one or multiple attachments can be added
* using EXTRA_STREAM .
* /
CharSequence text = intent . getCharSequenceExtra ( Intent . EXTRA_TEXT ) ;
2012-05-06 11:47:59 -04:00
// Only use EXTRA_TEXT if the body hasn't already been set by the mailto URI
if ( text ! = null & & mMessageContentView . getText ( ) . length ( ) = = 0 ) {
2013-10-08 19:14:08 -04:00
mMessageContentView . setCharacters ( text ) ;
2010-11-13 21:27:42 -05:00
}
String type = intent . getType ( ) ;
2011-02-06 17:09:48 -05:00
if ( Intent . ACTION_SEND . equals ( action ) ) {
2010-11-13 21:27:42 -05:00
Uri stream = ( Uri ) intent . getParcelableExtra ( Intent . EXTRA_STREAM ) ;
2011-02-06 17:09:48 -05:00
if ( stream ! = null ) {
2010-11-13 21:27:42 -05:00
addAttachment ( stream , type ) ;
}
2011-02-06 17:09:48 -05:00
} else {
2010-11-13 21:27:42 -05:00
ArrayList < Parcelable > list = intent . getParcelableArrayListExtra ( Intent . EXTRA_STREAM ) ;
2011-02-06 17:09:48 -05:00
if ( list ! = null ) {
for ( Parcelable parcelable : list ) {
2010-11-13 21:27:42 -05:00
Uri stream = ( Uri ) parcelable ;
2011-02-06 17:09:48 -05:00
if ( stream ! = null ) {
2010-11-13 21:27:42 -05:00
addAttachment ( stream , type ) ;
}
}
}
}
String subject = intent . getStringExtra ( Intent . EXTRA_SUBJECT ) ;
2012-05-06 11:47:59 -04:00
// Only use EXTRA_SUBJECT if the subject hasn't already been set by the mailto URI
if ( subject ! = null & & mSubjectView . getText ( ) . length ( ) = = 0 ) {
2010-11-13 21:27:42 -05:00
mSubjectView . setText ( subject ) ;
}
String [ ] extraEmail = intent . getStringArrayExtra ( Intent . EXTRA_EMAIL ) ;
String [ ] extraCc = intent . getStringArrayExtra ( Intent . EXTRA_CC ) ;
String [ ] extraBcc = intent . getStringArrayExtra ( Intent . EXTRA_BCC ) ;
2011-02-06 17:09:48 -05:00
if ( extraEmail ! = null ) {
2012-05-06 11:47:59 -04:00
addRecipients ( mToView , Arrays . asList ( extraEmail ) ) ;
2010-11-13 21:27:42 -05:00
}
boolean ccOrBcc = false ;
2011-02-06 17:09:48 -05:00
if ( extraCc ! = null ) {
2012-05-06 11:47:59 -04:00
ccOrBcc | = addRecipients ( mCcView , Arrays . asList ( extraCc ) ) ;
2010-11-13 21:27:42 -05:00
}
2011-02-06 17:09:48 -05:00
if ( extraBcc ! = null ) {
2012-05-06 11:47:59 -04:00
ccOrBcc | = addRecipients ( mBccView , Arrays . asList ( extraBcc ) ) ;
2010-11-13 21:27:42 -05:00
}
2011-02-06 17:09:48 -05:00
if ( ccOrBcc ) {
2010-11-13 21:27:42 -05:00
// Display CC and BCC text fields if CC or BCC recipients were set by the intent.
onAddCcBcc ( ) ;
}
}
2012-05-19 21:13:58 -04:00
return startedByExternalIntent ;
2010-11-13 21:27:42 -05:00
}
2012-05-06 11:47:59 -04:00
private boolean addRecipients ( TextView view , List < String > recipients ) {
if ( recipients = = null | | recipients . size ( ) = = 0 ) {
return false ;
2010-11-13 21:27:42 -05:00
}
2012-05-06 11:47:59 -04:00
StringBuilder addressList = new StringBuilder ( ) ;
// Read current contents of the TextView
String text = view . getText ( ) . toString ( ) ;
addressList . append ( text ) ;
// Add comma if necessary
if ( text . length ( ) ! = 0 & & ! ( text . endsWith ( " , " ) | | text . endsWith ( " , " ) ) ) {
addressList . append ( " , " ) ;
}
// Add recipients
for ( String recipient : recipients ) {
addressList . append ( recipient ) ;
addressList . append ( " , " ) ;
}
view . setText ( addressList ) ;
return true ;
2010-11-13 21:27:42 -05:00
}
2011-02-06 17:09:48 -05:00
private void initializeCrypto ( ) {
if ( mPgpData ! = null ) {
2010-07-27 08:10:09 -04:00
return ;
}
2010-08-22 05:51:17 -04:00
mPgpData = new PgpData ( ) ;
2010-07-27 08:10:09 -04:00
}
/ * *
* Fill the encrypt layout with the latest data about signature key and encryption keys .
* /
2011-02-06 17:09:48 -05:00
public void updateEncryptLayout ( ) {
if ( ! mPgpData . hasSignatureKey ( ) ) {
2010-07-27 08:10:09 -04:00
mCryptoSignatureCheckbox . setText ( R . string . btn_crypto_sign ) ;
mCryptoSignatureCheckbox . setChecked ( false ) ;
mCryptoSignatureUserId . setVisibility ( View . INVISIBLE ) ;
mCryptoSignatureUserIdRest . setVisibility ( View . INVISIBLE ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-07-27 08:10:09 -04:00
// if a signature key is selected, then the checkbox itself has no text
mCryptoSignatureCheckbox . setText ( " " ) ;
mCryptoSignatureCheckbox . setChecked ( true ) ;
mCryptoSignatureUserId . setVisibility ( View . VISIBLE ) ;
mCryptoSignatureUserIdRest . setVisibility ( View . VISIBLE ) ;
mCryptoSignatureUserId . setText ( R . string . unknown_crypto_signature_user_id ) ;
mCryptoSignatureUserIdRest . setText ( " " ) ;
2010-08-22 05:51:17 -04:00
String userId = mPgpData . getSignatureUserId ( ) ;
2011-02-06 17:09:48 -05:00
if ( userId = = null ) {
2010-08-22 05:51:17 -04:00
userId = mAccount . getCryptoProvider ( ) . getUserId ( this , mPgpData . getSignatureKeyId ( ) ) ;
mPgpData . setSignatureUserId ( userId ) ;
2010-07-27 08:10:09 -04:00
}
2011-02-06 17:09:48 -05:00
if ( userId ! = null ) {
2010-08-22 05:51:17 -04:00
String chunks [ ] = mPgpData . getSignatureUserId ( ) . split ( " < " , 2 ) ;
2010-07-27 08:10:09 -04:00
mCryptoSignatureUserId . setText ( chunks [ 0 ] ) ;
2011-02-06 17:09:48 -05:00
if ( chunks . length > 1 ) {
2010-07-27 08:10:09 -04:00
mCryptoSignatureUserIdRest . setText ( " < " + chunks [ 1 ] ) ;
}
}
}
2012-05-20 16:44:32 -04:00
updateMessageFormat ( ) ;
2010-07-27 08:10:09 -04:00
}
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public void onResume ( ) {
2008-11-01 17:32:06 -04:00
super . onResume ( ) ;
2012-01-22 00:25:06 -05:00
mIgnoreOnPause = false ;
2008-11-01 17:32:06 -04:00
MessagingController . getInstance ( getApplication ( ) ) . addListener ( mListener ) ;
}
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public void onPause ( ) {
2008-11-01 17:32:06 -04:00
super . onPause ( ) ;
MessagingController . getInstance ( getApplication ( ) ) . removeListener ( mListener ) ;
2011-11-04 03:33:56 -04:00
// Save email as draft when activity is changed (go to home screen, call received) or screen locked
2011-11-01 23:12:51 -04:00
// don't do this if only changing orientations
2012-01-22 00:25:06 -05:00
if ( ! mIgnoreOnPause & & ( getChangingConfigurations ( ) & ActivityInfo . CONFIG_ORIENTATION ) = = 0 ) {
2012-01-21 23:32:52 -05:00
saveIfNeeded ( ) ;
2011-11-01 23:12:51 -04:00
}
2008-11-01 17:32:06 -04:00
}
/ * *
* The framework handles most of the fields , but we need to handle stuff that we
* dynamically show and hide :
* Attachment list ,
* Cc field ,
* Bcc field ,
* Quoted text ,
* /
@Override
2011-02-06 17:09:48 -05:00
protected void onSaveInstanceState ( Bundle outState ) {
2008-11-01 17:32:06 -04:00
super . onSaveInstanceState ( outState ) ;
2013-08-14 12:05:57 -04:00
ArrayList < Attachment > attachments = new ArrayList < Attachment > ( ) ;
2011-02-06 17:09:48 -05:00
for ( int i = 0 , count = mAttachments . getChildCount ( ) ; i < count ; i + + ) {
2008-11-01 17:32:06 -04:00
View view = mAttachments . getChildAt ( i ) ;
Attachment attachment = ( Attachment ) view . getTag ( ) ;
2013-08-14 12:05:57 -04:00
attachments . add ( attachment ) ;
2008-11-01 17:32:06 -04:00
}
2013-08-14 12:05:57 -04:00
2013-09-24 21:46:11 -04:00
outState . putInt ( STATE_KEY_NUM_ATTACHMENTS_LOADING , mNumAttachmentsLoading ) ;
outState . putString ( STATE_KEY_WAITING_FOR_ATTACHMENTS , mWaitingForAttachments . name ( ) ) ;
2008-11-01 17:32:06 -04:00
outState . putParcelableArrayList ( STATE_KEY_ATTACHMENTS , attachments ) ;
2011-07-06 22:59:45 -04:00
outState . putBoolean ( STATE_KEY_CC_SHOWN , mCcWrapper . getVisibility ( ) = = View . VISIBLE ) ;
outState . putBoolean ( STATE_KEY_BCC_SHOWN , mBccWrapper . getVisibility ( ) = = View . VISIBLE ) ;
2011-05-10 11:54:17 -04:00
outState . putSerializable ( STATE_KEY_QUOTED_TEXT_MODE , mQuotedTextMode ) ;
2008-11-01 17:32:06 -04:00
outState . putBoolean ( STATE_KEY_SOURCE_MESSAGE_PROCED , mSourceMessageProcessed ) ;
2012-01-21 23:14:58 -05:00
outState . putLong ( STATE_KEY_DRAFT_ID , mDraftId ) ;
2009-06-08 23:11:35 -04:00
outState . putSerializable ( STATE_IDENTITY , mIdentity ) ;
outState . putBoolean ( STATE_IDENTITY_CHANGED , mIdentityChanged ) ;
2010-08-22 05:51:17 -04:00
outState . putSerializable ( STATE_PGP_DATA , mPgpData ) ;
2010-07-02 17:17:06 -04:00
outState . putString ( STATE_IN_REPLY_TO , mInReplyTo ) ;
outState . putString ( STATE_REFERENCES , mReferences ) ;
2011-01-12 18:48:28 -05:00
outState . putSerializable ( STATE_KEY_HTML_QUOTE , mQuotedHtmlContent ) ;
2011-08-27 20:42:27 -04:00
outState . putBoolean ( STATE_KEY_READ_RECEIPT , mReadReceipt ) ;
2011-11-01 04:02:29 -04:00
outState . putBoolean ( STATE_KEY_DRAFT_NEEDS_SAVING , mDraftNeedsSaving ) ;
2012-05-20 16:44:32 -04:00
outState . putBoolean ( STATE_KEY_FORCE_PLAIN_TEXT , mForcePlainText ) ;
outState . putSerializable ( STATE_KEY_QUOTED_TEXT_FORMAT , mQuotedTextFormat ) ;
2008-11-01 17:32:06 -04:00
}
@Override
2011-02-06 17:09:48 -05:00
protected void onRestoreInstanceState ( Bundle savedInstanceState ) {
2008-11-01 17:32:06 -04:00
super . onRestoreInstanceState ( savedInstanceState ) ;
2013-08-14 12:05:57 -04:00
2008-11-01 17:32:06 -04:00
mAttachments . removeAllViews ( ) ;
2013-08-14 12:05:57 -04:00
mMaxLoaderId = 0 ;
2013-09-24 21:46:11 -04:00
mNumAttachmentsLoading = savedInstanceState . getInt ( STATE_KEY_NUM_ATTACHMENTS_LOADING ) ;
mWaitingForAttachments = WaitingAction . NONE ;
try {
String waitingFor = savedInstanceState . getString ( STATE_KEY_WAITING_FOR_ATTACHMENTS ) ;
mWaitingForAttachments = WaitingAction . valueOf ( waitingFor ) ;
} catch ( Exception e ) {
Log . w ( K9 . LOG_TAG , " Couldn't read value \" + STATE_KEY_WAITING_FOR_ATTACHMENTS + " +
" \" from saved instance state " , e ) ;
}
2013-08-14 12:05:57 -04:00
ArrayList < Attachment > attachments = savedInstanceState . getParcelableArrayList ( STATE_KEY_ATTACHMENTS ) ;
for ( Attachment attachment : attachments ) {
addAttachmentView ( attachment ) ;
if ( attachment . loaderId > mMaxLoaderId ) {
mMaxLoaderId = attachment . loaderId ;
}
if ( attachment . state = = Attachment . LoadingState . URI_ONLY ) {
initAttachmentInfoLoader ( attachment ) ;
} else if ( attachment . state = = Attachment . LoadingState . METADATA ) {
initAttachmentContentLoader ( attachment ) ;
}
2008-11-01 17:32:06 -04:00
}
2011-08-27 20:42:27 -04:00
mReadReceipt = savedInstanceState
2011-11-14 16:58:01 -05:00
. getBoolean ( STATE_KEY_READ_RECEIPT ) ;
2011-03-22 03:06:11 -04:00
mCcWrapper . setVisibility ( savedInstanceState . getBoolean ( STATE_KEY_CC_SHOWN ) ? View . VISIBLE
: View . GONE ) ;
mBccWrapper . setVisibility ( savedInstanceState
. getBoolean ( STATE_KEY_BCC_SHOWN ) ? View . VISIBLE : View . GONE ) ;
2012-05-20 16:44:32 -04:00
2012-09-13 22:26:57 -04:00
// This method is called after the action bar menu has already been created and prepared.
// So compute the visibility of the "Add Cc/Bcc" menu item again.
computeAddCcBccVisibility ( ) ;
2012-05-20 16:44:32 -04:00
mQuotedHtmlContent =
( InsertableHtmlContent ) savedInstanceState . getSerializable ( STATE_KEY_HTML_QUOTE ) ;
if ( mQuotedHtmlContent ! = null & & mQuotedHtmlContent . getQuotedContent ( ) ! = null ) {
2013-03-01 11:26:52 -05:00
mQuotedHTML . setText ( mQuotedHtmlContent . getQuotedContent ( ) ) ;
2011-01-12 18:48:28 -05:00
}
2012-05-20 16:44:32 -04:00
2012-01-21 23:14:58 -05:00
mDraftId = savedInstanceState . getLong ( STATE_KEY_DRAFT_ID ) ;
2010-03-03 23:00:30 -05:00
mIdentity = ( Identity ) savedInstanceState . getSerializable ( STATE_IDENTITY ) ;
2009-06-08 23:11:35 -04:00
mIdentityChanged = savedInstanceState . getBoolean ( STATE_IDENTITY_CHANGED ) ;
2010-08-22 05:51:17 -04:00
mPgpData = ( PgpData ) savedInstanceState . getSerializable ( STATE_PGP_DATA ) ;
2010-07-02 17:17:06 -04:00
mInReplyTo = savedInstanceState . getString ( STATE_IN_REPLY_TO ) ;
mReferences = savedInstanceState . getString ( STATE_REFERENCES ) ;
2011-11-01 04:02:29 -04:00
mDraftNeedsSaving = savedInstanceState . getBoolean ( STATE_KEY_DRAFT_NEEDS_SAVING ) ;
2012-05-20 16:44:32 -04:00
mForcePlainText = savedInstanceState . getBoolean ( STATE_KEY_FORCE_PLAIN_TEXT ) ;
mQuotedTextFormat = ( SimpleMessageFormat ) savedInstanceState . getSerializable (
STATE_KEY_QUOTED_TEXT_FORMAT ) ;
2010-07-27 08:10:09 -04:00
2014-01-22 19:35:21 -05:00
showOrHideQuotedText (
( QuotedTextMode ) savedInstanceState . getSerializable ( STATE_KEY_QUOTED_TEXT_MODE ) ) ;
2010-07-27 08:10:09 -04:00
initializeCrypto ( ) ;
2009-06-08 23:11:35 -04:00
updateFrom ( ) ;
updateSignature ( ) ;
2010-07-27 08:10:09 -04:00
updateEncryptLayout ( ) ;
2009-11-21 17:45:39 -05:00
2012-05-20 16:44:32 -04:00
updateMessageFormat ( ) ;
2008-11-01 17:32:06 -04:00
}
2012-11-20 19:42:19 -05:00
private void setTitle ( ) {
switch ( mAction ) {
case REPLY : {
setTitle ( R . string . compose_title_reply ) ;
break ;
}
case REPLY_ALL : {
setTitle ( R . string . compose_title_reply_all ) ;
break ;
}
case FORWARD : {
setTitle ( R . string . compose_title_forward ) ;
break ;
}
case COMPOSE :
default : {
setTitle ( R . string . compose_title_compose ) ;
break ;
}
2008-11-01 17:32:06 -04:00
}
}
2012-02-18 10:26:28 -05:00
private void addAddresses ( MultiAutoCompleteTextView view , String addresses ) {
if ( StringUtils . isNullOrEmpty ( addresses ) ) {
return ;
}
for ( String address : addresses . split ( " , " ) ) {
addAddress ( view , new Address ( address , " " ) ) ;
}
}
2011-02-06 17:09:48 -05:00
private void addAddresses ( MultiAutoCompleteTextView view , Address [ ] addresses ) {
if ( addresses = = null ) {
2008-11-01 17:32:06 -04:00
return ;
}
2011-02-06 17:09:48 -05:00
for ( Address address : addresses ) {
2008-11-01 17:32:06 -04:00
addAddress ( view , address ) ;
}
}
2011-02-06 17:09:48 -05:00
private void addAddress ( MultiAutoCompleteTextView view , Address address ) {
2008-11-01 17:32:06 -04:00
view . append ( address + " , " ) ;
}
2011-02-06 17:09:48 -05:00
private Address [ ] getAddresses ( MultiAutoCompleteTextView view ) {
2010-11-30 22:00:36 -05:00
return Address . parseUnencoded ( view . getText ( ) . toString ( ) . trim ( ) ) ;
2008-11-01 17:32:06 -04:00
}
2011-11-21 02:59:51 -05:00
/ *
* Returns an Address array of recipients this email will be sent to .
* @return Address array of recipients this email will be sent to .
* /
2011-11-19 01:49:04 -05:00
private Address [ ] getRecipientAddresses ( ) {
String addresses = mToView . getText ( ) . toString ( ) + mCcView . getText ( ) . toString ( )
+ mBccView . getText ( ) . toString ( ) ;
return Address . parseUnencoded ( addresses . trim ( ) ) ;
}
2010-08-30 17:27:07 -04:00
/ *
* Build the Body that will contain the text of the message . We ' ll decide where to
2011-01-12 18:48:28 -05:00
* include it later . Draft messages are treated somewhat differently in that signatures are not
* appended and HTML separators between composed text and quoted text are not added .
* @param isDraft If we should build a message that will be saved as a draft ( as opposed to sent ) .
2010-08-30 17:27:07 -04:00
* /
2011-02-06 17:09:48 -05:00
private TextBody buildText ( boolean isDraft ) {
2011-11-14 16:16:19 -05:00
return buildText ( isDraft , mMessageFormat ) ;
}
2012-01-09 19:47:23 -05:00
/ * *
* Build the { @link Body } that will contain the text of the message .
*
* < p >
* Draft messages are treated somewhat differently in that signatures are not appended and HTML
* separators between composed text and quoted text are not added .
* < / p >
*
* @param isDraft
* If { @code true } we build a message that will be saved as a draft ( as opposed to
* sent ) .
* @param messageFormat
* Specifies what type of message to build ( { @code text / plain } vs . { @code text / html } ) .
*
* @return { @link TextBody } instance that contains the entered text and possibly the quoted
* original message .
2011-11-14 16:16:19 -05:00
* /
2012-05-20 16:44:32 -04:00
private TextBody buildText ( boolean isDraft , SimpleMessageFormat messageFormat ) {
2012-01-09 19:47:23 -05:00
// The length of the formatted version of the user-supplied text/reply
int composedMessageLength ;
2010-07-27 08:10:09 -04:00
2012-01-09 19:47:23 -05:00
// The offset of the user-supplied text/reply in the final text body
int composedMessageOffset ;
2010-07-27 08:10:09 -04:00
2012-01-09 19:47:23 -05:00
/ *
2012-01-10 01:44:50 -05:00
* Find out if we need to include the original message as quoted text .
2012-01-09 19:47:23 -05:00
*
* We include the quoted text in the body if the user didn ' t choose to hide it . We always
* include the quoted text when we ' re saving a draft . That ' s so the user is able to
* " un-hide " the quoted text if ( s ) he opens a saved draft .
* /
2012-01-10 01:44:50 -05:00
boolean includeQuotedText = ( mQuotedTextMode . equals ( QuotedTextMode . SHOW ) | | isDraft ) ;
2012-01-09 19:47:23 -05:00
// Reply after quote makes no sense for HEADER style replies
boolean replyAfterQuote = ( mQuoteStyle = = QuoteStyle . HEADER ) ?
false : mAccount . isReplyAfterQuote ( ) ;
2011-07-02 15:18:43 -04:00
2012-01-09 19:47:23 -05:00
boolean signatureBeforeQuotedText = mAccount . isSignatureBeforeQuotedText ( ) ;
2011-05-10 11:54:17 -04:00
2012-01-09 19:47:23 -05:00
// Get the user-supplied text
2013-10-08 19:14:08 -04:00
String text = mMessageContentView . getCharacters ( ) ;
2012-01-09 19:47:23 -05:00
// Handle HTML separate from the rest of the text content
2012-05-20 16:44:32 -04:00
if ( messageFormat = = SimpleMessageFormat . HTML ) {
2012-01-09 19:47:23 -05:00
// Do we have to modify an existing message to include our reply?
2012-01-10 01:44:50 -05:00
if ( includeQuotedText & & mQuotedHtmlContent ! = null ) {
2012-01-09 19:47:23 -05:00
if ( K9 . DEBUG ) {
Log . d ( K9 . LOG_TAG , " insertable: " + mQuotedHtmlContent . toDebugString ( ) ) ;
2011-11-14 16:16:19 -05:00
}
2012-01-09 19:47:23 -05:00
if ( ! isDraft ) {
// Append signature to the reply
if ( replyAfterQuote | | signatureBeforeQuotedText ) {
text = appendSignature ( text ) ;
}
}
// Convert the text to HTML
text = HtmlConverter . textToHtmlFragment ( text ) ;
/ *
* Set the insertion location based upon our reply after quote setting .
* Additionally , add some extra separators between the composed message and quoted
* message depending on the quote location . We only add the extra separators when
* we ' re sending , that way when we load a draft , we don ' t have to know the length
* of the separators to remove them before editing .
* /
if ( replyAfterQuote ) {
mQuotedHtmlContent . setInsertionLocation (
InsertableHtmlContent . InsertionLocation . AFTER_QUOTE ) ;
2011-02-06 17:09:48 -05:00
if ( ! isDraft ) {
2011-01-28 16:41:06 -05:00
text = " <br clear= \" all \" > " + text ;
2011-01-24 22:56:19 -05:00
}
2011-02-06 17:09:48 -05:00
} else {
2012-01-09 19:47:23 -05:00
mQuotedHtmlContent . setInsertionLocation (
InsertableHtmlContent . InsertionLocation . BEFORE_QUOTE ) ;
2011-02-06 17:09:48 -05:00
if ( ! isDraft ) {
2011-01-28 16:41:06 -05:00
text + = " <br><br> " ;
2011-01-24 22:56:19 -05:00
}
2011-01-12 18:48:28 -05:00
}
2011-01-28 16:41:06 -05:00
2011-11-14 16:16:19 -05:00
if ( ! isDraft ) {
2012-01-09 19:47:23 -05:00
// Place signature immediately after the quoted text
if ( ! ( replyAfterQuote | | signatureBeforeQuotedText ) ) {
2011-11-14 16:16:19 -05:00
mQuotedHtmlContent . insertIntoQuotedFooter ( getSignatureHtml ( ) ) ;
}
}
2011-01-28 16:41:06 -05:00
mQuotedHtmlContent . setUserContent ( text ) ;
2011-01-12 18:48:28 -05:00
// Save length of the body and its offset. This is used when thawing drafts.
2012-01-09 19:47:23 -05:00
composedMessageLength = text . length ( ) ;
composedMessageOffset = mQuotedHtmlContent . getInsertionPoint ( ) ;
text = mQuotedHtmlContent . toString ( ) ;
2011-02-06 17:09:48 -05:00
} else {
2012-01-09 19:47:23 -05:00
// There is no text to quote so simply append the signature if available
if ( ! isDraft ) {
text = appendSignature ( text ) ;
}
// Convert the text to HTML
text = HtmlConverter . textToHtmlFragment ( text ) ;
//TODO: Wrap this in proper HTML tags
composedMessageLength = text . length ( ) ;
composedMessageOffset = 0 ;
2010-08-30 17:27:07 -04:00
}
2012-01-09 19:47:23 -05:00
} else {
2011-01-12 18:48:28 -05:00
// Capture composed message length before we start attaching quoted parts and signatures.
2012-01-09 19:47:23 -05:00
composedMessageLength = text . length ( ) ;
composedMessageOffset = 0 ;
2011-01-12 18:48:28 -05:00
2011-06-15 11:35:27 -04:00
if ( ! isDraft ) {
2012-01-09 19:47:23 -05:00
// Append signature to the text/reply
if ( replyAfterQuote | | signatureBeforeQuotedText ) {
2011-06-15 11:35:27 -04:00
text = appendSignature ( text ) ;
}
2011-01-12 18:48:28 -05:00
}
2013-10-08 18:30:21 -04:00
String quotedText = mQuotedText . getCharacters ( ) ;
if ( includeQuotedText & & quotedText . length ( ) > 0 ) {
2012-01-09 19:47:23 -05:00
if ( replyAfterQuote ) {
2013-10-08 17:07:21 -04:00
composedMessageOffset = quotedText . length ( ) + " \ r \ n " . length ( ) ;
text = quotedText + " \ r \ n " + text ;
2011-02-06 17:09:48 -05:00
} else {
2013-10-08 17:07:21 -04:00
text + = " \ r \ n \ r \ n " + quotedText . toString ( ) ;
2011-01-12 18:48:28 -05:00
}
}
2011-06-15 11:35:27 -04:00
if ( ! isDraft ) {
2012-01-09 19:47:23 -05:00
// Place signature immediately after the quoted text
if ( ! ( replyAfterQuote | | signatureBeforeQuotedText ) ) {
2011-06-15 11:35:27 -04:00
text = appendSignature ( text ) ;
}
2011-01-12 18:48:28 -05:00
}
2010-07-27 08:10:09 -04:00
}
2012-01-09 19:47:23 -05:00
TextBody body = new TextBody ( text ) ;
body . setComposedMessageLength ( composedMessageLength ) ;
body . setComposedMessageOffset ( composedMessageOffset ) ;
return body ;
2010-07-27 08:10:09 -04:00
}
2011-01-12 18:48:28 -05:00
/ * *
* Build the final message to be sent ( or saved ) . If there is another message quoted in this one , it will be baked
* into the final message here .
* @param isDraft Indicates if this message is a draft or not . Drafts do not have signatures
* appended and have some extra metadata baked into their header for use during thawing .
* @return Message to be sent .
* @throws MessagingException
* /
2011-02-06 17:09:48 -05:00
private MimeMessage createMessage ( boolean isDraft ) throws MessagingException {
2008-11-01 17:32:06 -04:00
MimeMessage message = new MimeMessage ( ) ;
2009-09-25 15:12:37 -04:00
message . addSentDate ( new Date ( ) ) ;
2009-06-08 23:11:35 -04:00
Address from = new Address ( mIdentity . getEmail ( ) , mIdentity . getName ( ) ) ;
2008-11-01 17:32:06 -04:00
message . setFrom ( from ) ;
message . setRecipients ( RecipientType . TO , getAddresses ( mToView ) ) ;
message . setRecipients ( RecipientType . CC , getAddresses ( mCcView ) ) ;
message . setRecipients ( RecipientType . BCC , getAddresses ( mBccView ) ) ;
message . setSubject ( mSubjectView . getText ( ) . toString ( ) ) ;
2011-08-28 19:08:41 -04:00
if ( mReadReceipt ) {
2011-08-27 20:42:27 -04:00
message . setHeader ( " Disposition-Notification-To " , from . toEncodedString ( ) ) ;
2011-08-28 19:08:41 -04:00
message . setHeader ( " X-Confirm-Reading-To " , from . toEncodedString ( ) ) ;
message . setHeader ( " Return-Receipt-To " , from . toEncodedString ( ) ) ;
2011-08-27 20:42:27 -04:00
}
2011-01-04 03:33:12 -05:00
message . setHeader ( " User-Agent " , getString ( R . string . message_header_mua ) ) ;
2009-11-21 17:45:39 -05:00
2010-06-20 08:48:22 -04:00
final String replyTo = mIdentity . getReplyTo ( ) ;
2011-02-06 17:09:48 -05:00
if ( replyTo ! = null ) {
2010-06-20 08:48:22 -04:00
message . setReplyTo ( new Address [ ] { new Address ( replyTo ) } ) ;
}
2011-02-06 17:09:48 -05:00
if ( mInReplyTo ! = null ) {
2009-11-21 17:45:39 -05:00
message . setInReplyTo ( mInReplyTo ) ;
2009-11-17 16:13:29 -05:00
}
2009-11-21 17:45:39 -05:00
2011-02-06 17:09:48 -05:00
if ( mReferences ! = null ) {
2009-11-21 17:45:39 -05:00
message . setReferences ( mReferences ) ;
2009-11-17 16:13:29 -05:00
}
2009-11-21 17:45:39 -05:00
2011-01-12 18:48:28 -05:00
// Build the body.
2012-01-09 19:47:23 -05:00
// TODO FIXME - body can be either an HTML or Text part, depending on whether we're in
2011-11-14 16:16:19 -05:00
// HTML mode or not. Should probably fix this so we don't mix up html and text parts.
2011-01-12 18:48:28 -05:00
TextBody body = null ;
2011-02-06 17:09:48 -05:00
if ( mPgpData . getEncryptedData ( ) ! = null ) {
2011-01-12 18:48:28 -05:00
String text = mPgpData . getEncryptedData ( ) ;
body = new TextBody ( text ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-01-12 18:48:28 -05:00
body = buildText ( isDraft ) ;
}
2011-11-14 16:16:19 -05:00
// text/plain part when mMessageFormat == MessageFormat.HTML
TextBody bodyPlain = null ;
2011-01-12 18:48:28 -05:00
final boolean hasAttachments = mAttachments . getChildCount ( ) > 0 ;
2012-05-20 16:44:32 -04:00
if ( mMessageFormat = = SimpleMessageFormat . HTML ) {
2011-01-12 18:48:28 -05:00
// HTML message (with alternative text part)
// This is the compiled MIME part for an HTML message.
MimeMultipart composedMimeMessage = new MimeMultipart ( ) ;
composedMimeMessage . setSubType ( " alternative " ) ; // Let the receiver select either the text or the HTML part.
composedMimeMessage . addBodyPart ( new MimeBodyPart ( body , " text/html " ) ) ;
2012-05-20 16:44:32 -04:00
bodyPlain = buildText ( isDraft , SimpleMessageFormat . TEXT ) ;
2011-11-14 16:16:19 -05:00
composedMimeMessage . addBodyPart ( new MimeBodyPart ( bodyPlain , " text/plain " ) ) ;
2011-01-12 18:48:28 -05:00
2011-02-06 17:09:48 -05:00
if ( hasAttachments ) {
2011-01-12 18:48:28 -05:00
// If we're HTML and have attachments, we have a MimeMultipart container to hold the
// whole message (mp here), of which one part is a MimeMultipart container
// (composedMimeMessage) with the user's composed messages, and subsequent parts for
// the attachments.
MimeMultipart mp = new MimeMultipart ( ) ;
mp . addBodyPart ( new MimeBodyPart ( composedMimeMessage ) ) ;
addAttachmentsToMessage ( mp ) ;
message . setBody ( mp ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-01-12 18:48:28 -05:00
// If no attachments, our multipart/alternative part is the only one we need.
message . setBody ( composedMimeMessage ) ;
}
2012-05-20 16:44:32 -04:00
} else if ( mMessageFormat = = SimpleMessageFormat . TEXT ) {
2011-01-12 18:48:28 -05:00
// Text-only message.
2011-02-06 17:09:48 -05:00
if ( hasAttachments ) {
2011-01-12 18:48:28 -05:00
MimeMultipart mp = new MimeMultipart ( ) ;
mp . addBodyPart ( new MimeBodyPart ( body , " text/plain " ) ) ;
addAttachmentsToMessage ( mp ) ;
message . setBody ( mp ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-01-12 18:48:28 -05:00
// No attachments to include, just stick the text body in the message and call it good.
message . setBody ( body ) ;
}
}
// If this is a draft, add metadata for thawing.
2011-02-06 17:09:48 -05:00
if ( isDraft ) {
2011-01-12 18:48:28 -05:00
// Add the identity to the message.
2011-11-14 16:16:19 -05:00
message . addHeader ( K9 . IDENTITY_HEADER , buildIdentityHeader ( body , bodyPlain ) ) ;
2009-06-08 23:11:35 -04:00
}
2011-01-12 18:48:28 -05:00
return message ;
}
2008-11-01 17:32:06 -04:00
2011-01-12 18:48:28 -05:00
/ * *
* Add attachments as parts into a MimeMultipart container .
* @param mp MimeMultipart container in which to insert parts .
* @throws MessagingException
* /
2011-02-06 17:09:48 -05:00
private void addAttachmentsToMessage ( final MimeMultipart mp ) throws MessagingException {
2013-09-24 21:54:35 -04:00
Body body ;
2011-02-06 17:09:48 -05:00
for ( int i = 0 , count = mAttachments . getChildCount ( ) ; i < count ; i + + ) {
2011-01-12 18:48:28 -05:00
Attachment attachment = ( Attachment ) mAttachments . getChildAt ( i ) . getTag ( ) ;
2013-08-14 12:05:57 -04:00
if ( attachment . state ! = Attachment . LoadingState . COMPLETE ) {
continue ;
}
Don't base64 encode attachments of type message/rfc822.
The problem: Receive a message with an attachment of type message/rfc822
and forward it. When the message is sent, K-9 Mail uses base64 encoding
for the attachment. (Alternatively, you could compose a new message and
add such an attachment from a file using a filing-picking app, but that is
not 100% effective because the app may not choose the correct
message/rfc822 MIME type for the attachment.)
Such encoding is prohibited per RFC 2046 (5.2.1) and RFC 2045 (6.4). Only
8bit or 7bit encoding is permitted for attachments of type message/rfc822.
Thunderbird refuses to decode such attachments. All that is shown is the
base64 encoded body.
This commit implements LocalAttachmentBody.setEncoding. If an attachment
to a newly composed message is itself a message, then setEncoding("8bit")
is called, otherwise setEncoding("base64") is called for the attachment.
Similar behavior occurs when an attachment is retrieved from LocalStore.
The setEncoding method was added to the Body interface, since all
implementations of Body now declare the method.
The problem here differs from that in the preceding commit: Here, the
encoding problem occurs on sending, not on receipt. Here, the entire
message (headers and body) is base64 encoded, not just the body. Here,
the headers correctly identify the encoding used; it's just that the RFC
does not permit such encoding of attached messages. The problem here
could in fact occur in combination with the preceding problem.
2013-09-01 16:25:09 -04:00
String contentType = attachment . contentType ;
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
if ( MimeUtil . isMessage ( contentType ) ) {
2013-09-24 21:54:35 -04:00
body = new TempFileMessageBody ( attachment . filename ) ;
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
} else {
2013-09-24 21:54:35 -04:00
body = new TempFileBody ( attachment . filename ) ;
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
}
Don't base64 encode attachments of type message/rfc822.
The problem: Receive a message with an attachment of type message/rfc822
and forward it. When the message is sent, K-9 Mail uses base64 encoding
for the attachment. (Alternatively, you could compose a new message and
add such an attachment from a file using a filing-picking app, but that is
not 100% effective because the app may not choose the correct
message/rfc822 MIME type for the attachment.)
Such encoding is prohibited per RFC 2046 (5.2.1) and RFC 2045 (6.4). Only
8bit or 7bit encoding is permitted for attachments of type message/rfc822.
Thunderbird refuses to decode such attachments. All that is shown is the
base64 encoded body.
This commit implements LocalAttachmentBody.setEncoding. If an attachment
to a newly composed message is itself a message, then setEncoding("8bit")
is called, otherwise setEncoding("base64") is called for the attachment.
Similar behavior occurs when an attachment is retrieved from LocalStore.
The setEncoding method was added to the Body interface, since all
implementations of Body now declare the method.
The problem here differs from that in the preceding commit: Here, the
encoding problem occurs on sending, not on receipt. Here, the entire
message (headers and body) is base64 encoded, not just the body. Here,
the headers correctly identify the encoding used; it's just that the RFC
does not permit such encoding of attached messages. The problem here
could in fact occur in combination with the preceding problem.
2013-09-01 16:25:09 -04:00
MimeBodyPart bp = new MimeBodyPart ( body ) ;
2011-01-12 18:48:28 -05:00
2008-11-01 17:32:06 -04:00
/ *
2011-01-12 18:48:28 -05:00
* Correctly encode the filename here . Otherwise the whole
* header value ( all parameters at once ) will be encoded by
* MimeHeader . writeTo ( ) .
2008-11-01 17:32:06 -04:00
* /
2013-10-08 17:07:21 -04:00
bp . addHeader ( MimeHeader . HEADER_CONTENT_TYPE , String . format ( " %s; \ r \ n name= \" %s \" " ,
Don't base64 encode attachments of type message/rfc822.
The problem: Receive a message with an attachment of type message/rfc822
and forward it. When the message is sent, K-9 Mail uses base64 encoding
for the attachment. (Alternatively, you could compose a new message and
add such an attachment from a file using a filing-picking app, but that is
not 100% effective because the app may not choose the correct
message/rfc822 MIME type for the attachment.)
Such encoding is prohibited per RFC 2046 (5.2.1) and RFC 2045 (6.4). Only
8bit or 7bit encoding is permitted for attachments of type message/rfc822.
Thunderbird refuses to decode such attachments. All that is shown is the
base64 encoded body.
This commit implements LocalAttachmentBody.setEncoding. If an attachment
to a newly composed message is itself a message, then setEncoding("8bit")
is called, otherwise setEncoding("base64") is called for the attachment.
Similar behavior occurs when an attachment is retrieved from LocalStore.
The setEncoding method was added to the Body interface, since all
implementations of Body now declare the method.
The problem here differs from that in the preceding commit: Here, the
encoding problem occurs on sending, not on receipt. Here, the entire
message (headers and body) is base64 encoded, not just the body. Here,
the headers correctly identify the encoding used; it's just that the RFC
does not permit such encoding of attached messages. The problem here
could in fact occur in combination with the preceding problem.
2013-09-01 16:25:09 -04:00
contentType ,
2011-01-12 18:48:28 -05:00
EncoderUtil . encodeIfNecessary ( attachment . name ,
EncoderUtil . Usage . WORD_ENTITY , 7 ) ) ) ;
2008-11-01 17:32:06 -04:00
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
bp . setEncoding ( MimeUtility . getEncodingforType ( contentType ) ) ;
2008-11-01 17:32:06 -04:00
2011-01-12 18:48:28 -05:00
/ *
* TODO : Oh the joys of MIME . . .
*
* From RFC 2183 ( The Content - Disposition Header Field ) :
* " Parameter values longer than 78 characters, or which
* contain non - ASCII characters , MUST be encoded as specified
* in [ RFC 2184 ] . "
*
* Example :
*
* Content - Type : application / x - stuff
* title * 1 * = us - ascii ' en ' This % 20is % 20even % 20more % 20
* title * 2 * = % 2A % 2A % 2Afun % 2A % 2A % 2A % 20
* title * 3 = " isn't it! "
* /
bp . addHeader ( MimeHeader . HEADER_CONTENT_DISPOSITION , String . format (
2013-10-08 17:07:21 -04:00
" attachment; \ r \ n filename= \" %s \" ; \ r \ n size=%d " ,
2011-06-09 21:54:22 -04:00
attachment . name , attachment . size ) ) ;
2008-11-01 17:32:06 -04:00
2011-01-12 18:48:28 -05:00
mp . addBodyPart ( bp ) ;
}
}
2010-05-11 11:05:50 -04:00
2011-01-12 18:48:28 -05:00
// FYI, there's nothing in the code that requires these variables to one letter. They're one
// letter simply to save space. This name sucks. It's too similar to Account.Identity.
2011-02-06 17:09:48 -05:00
private enum IdentityField {
2011-01-12 18:48:28 -05:00
LENGTH ( " l " ) ,
OFFSET ( " o " ) ,
2011-11-14 16:16:19 -05:00
FOOTER_OFFSET ( " fo " ) ,
PLAIN_LENGTH ( " pl " ) ,
PLAIN_OFFSET ( " po " ) ,
2011-01-12 18:48:28 -05:00
MESSAGE_FORMAT ( " f " ) ,
2011-08-27 20:42:27 -04:00
MESSAGE_READ_RECEIPT ( " r " ) ,
2011-01-12 18:48:28 -05:00
SIGNATURE ( " s " ) ,
NAME ( " n " ) ,
EMAIL ( " e " ) ,
// TODO - store a reference to the message being replied so we can mark it at the time of send.
2011-05-10 18:23:25 -04:00
ORIGINAL_MESSAGE ( " m " ) ,
2011-05-10 11:54:17 -04:00
CURSOR_POSITION ( " p " ) , // Where in the message your cursor was when you saved.
2011-11-14 16:16:19 -05:00
QUOTED_TEXT_MODE ( " q " ) ,
QUOTE_STYLE ( " qs " ) ;
2010-05-11 11:05:50 -04:00
2011-01-12 18:48:28 -05:00
private final String value ;
2010-05-11 11:05:50 -04:00
2011-02-06 17:09:48 -05:00
IdentityField ( String value ) {
2011-01-12 18:48:28 -05:00
this . value = value ;
}
2010-05-11 11:05:50 -04:00
2011-02-06 17:09:48 -05:00
public String value ( ) {
2011-01-12 18:48:28 -05:00
return value ;
}
2010-05-11 11:05:50 -04:00
2011-01-12 18:48:28 -05:00
/ * *
2012-01-22 00:25:06 -05:00
* Get the list of IdentityFields that should be integer values .
*
* < p >
* These values are sanity checked for integer - ness during decoding .
* < / p >
*
* @return The list of integer { @link IdentityField } s .
2011-01-12 18:48:28 -05:00
* /
2011-02-06 17:09:48 -05:00
public static IdentityField [ ] getIntegerFields ( ) {
2011-11-14 16:16:19 -05:00
return new IdentityField [ ] { LENGTH , OFFSET , FOOTER_OFFSET , PLAIN_LENGTH , PLAIN_OFFSET } ;
2011-01-12 18:48:28 -05:00
}
}
2011-02-03 01:32:29 -05:00
// Version identifier for "new style" identity. ! is an impossible value in base64 encoding, so we
// use that to determine which version we're in.
private static final String IDENTITY_VERSION_1 = " ! " ;
2011-11-14 16:16:19 -05:00
/ * *
* Build the identity header string . This string contains metadata about a draft message to be
* used upon loading a draft for composition . This should be generated at the time of saving a
* draft . < br >
* < br >
* This is a URL - encoded key / value pair string . The list of possible values are in { @link IdentityField } .
* @param body { @link TextBody } to analyze for body length and offset .
* @param bodyPlain { @link TextBody } to analyze for body length and offset . May be null .
* @return Identity string .
* /
private String buildIdentityHeader ( final TextBody body , final TextBody bodyPlain ) {
2011-01-12 18:48:28 -05:00
Uri . Builder uri = new Uri . Builder ( ) ;
2011-02-06 17:09:48 -05:00
if ( body . getComposedMessageLength ( ) ! = null & & body . getComposedMessageOffset ( ) ! = null ) {
2011-01-12 18:48:28 -05:00
// See if the message body length is already in the TextBody.
uri . appendQueryParameter ( IdentityField . LENGTH . value ( ) , body . getComposedMessageLength ( ) . toString ( ) ) ;
uri . appendQueryParameter ( IdentityField . OFFSET . value ( ) , body . getComposedMessageOffset ( ) . toString ( ) ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-01-12 18:48:28 -05:00
// If not, calculate it now.
uri . appendQueryParameter ( IdentityField . LENGTH . value ( ) , Integer . toString ( body . getText ( ) . length ( ) ) ) ;
uri . appendQueryParameter ( IdentityField . OFFSET . value ( ) , Integer . toString ( 0 ) ) ;
}
2011-11-14 16:16:19 -05:00
if ( mQuotedHtmlContent ! = null ) {
uri . appendQueryParameter ( IdentityField . FOOTER_OFFSET . value ( ) ,
Integer . toString ( mQuotedHtmlContent . getFooterInsertionPoint ( ) ) ) ;
}
if ( bodyPlain ! = null ) {
if ( bodyPlain . getComposedMessageLength ( ) ! = null & & bodyPlain . getComposedMessageOffset ( ) ! = null ) {
// See if the message body length is already in the TextBody.
uri . appendQueryParameter ( IdentityField . PLAIN_LENGTH . value ( ) , bodyPlain . getComposedMessageLength ( ) . toString ( ) ) ;
uri . appendQueryParameter ( IdentityField . PLAIN_OFFSET . value ( ) , bodyPlain . getComposedMessageOffset ( ) . toString ( ) ) ;
} else {
// If not, calculate it now.
uri . appendQueryParameter ( IdentityField . PLAIN_LENGTH . value ( ) , Integer . toString ( body . getText ( ) . length ( ) ) ) ;
uri . appendQueryParameter ( IdentityField . PLAIN_OFFSET . value ( ) , Integer . toString ( 0 ) ) ;
}
}
// Save the quote style (useful for forwards).
uri . appendQueryParameter ( IdentityField . QUOTE_STYLE . value ( ) , mQuoteStyle . name ( ) ) ;
2011-01-12 18:48:28 -05:00
// Save the message format for this offset.
2011-02-05 18:14:02 -05:00
uri . appendQueryParameter ( IdentityField . MESSAGE_FORMAT . value ( ) , mMessageFormat . name ( ) ) ;
2011-01-12 18:48:28 -05:00
// If we're not using the standard identity of signature, append it on to the identity blob.
2013-07-08 00:44:44 -04:00
if ( mIdentity . getSignatureUse ( ) & & mSignatureChanged ) {
2013-10-08 19:14:08 -04:00
uri . appendQueryParameter ( IdentityField . SIGNATURE . value ( ) , mSignatureView . getCharacters ( ) ) ;
2011-01-12 18:48:28 -05:00
}
2011-02-06 17:09:48 -05:00
if ( mIdentityChanged ) {
2011-01-12 18:48:28 -05:00
uri . appendQueryParameter ( IdentityField . NAME . value ( ) , mIdentity . getName ( ) ) ;
uri . appendQueryParameter ( IdentityField . EMAIL . value ( ) , mIdentity . getEmail ( ) ) ;
}
2011-02-06 17:09:48 -05:00
if ( mMessageReference ! = null ) {
2011-02-03 01:32:29 -05:00
uri . appendQueryParameter ( IdentityField . ORIGINAL_MESSAGE . value ( ) , mMessageReference . toIdentityString ( ) ) ;
}
2011-05-10 18:23:25 -04:00
uri . appendQueryParameter ( IdentityField . CURSOR_POSITION . value ( ) , Integer . toString ( mMessageContentView . getSelectionStart ( ) ) ) ;
2011-05-10 11:54:17 -04:00
uri . appendQueryParameter ( IdentityField . QUOTED_TEXT_MODE . value ( ) , mQuotedTextMode . name ( ) ) ;
2011-02-03 01:32:29 -05:00
String k9identity = IDENTITY_VERSION_1 + uri . build ( ) . getEncodedQuery ( ) ;
2011-01-12 18:48:28 -05:00
2011-02-06 17:09:48 -05:00
if ( K9 . DEBUG ) {
2011-01-12 18:48:28 -05:00
Log . d ( K9 . LOG_TAG , " Generated identity: " + k9identity ) ;
}
return k9identity ;
}
/ * *
* Parse an identity string . Handles both legacy and new ( ! ) style identities .
2012-01-22 00:25:06 -05:00
*
2011-01-12 18:48:28 -05:00
* @param identityString
2012-01-22 00:25:06 -05:00
* The encoded identity string that was saved in a drafts header .
*
* @return A map containing the value for each { @link IdentityField } in the identity string .
2011-01-12 18:48:28 -05:00
* /
2011-02-06 17:09:48 -05:00
private Map < IdentityField , String > parseIdentityHeader ( final String identityString ) {
2011-01-12 18:48:28 -05:00
Map < IdentityField , String > identity = new HashMap < IdentityField , String > ( ) ;
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Decoding identity: " + identityString ) ;
2011-02-06 17:09:48 -05:00
if ( identityString = = null | | identityString . length ( ) < 1 ) {
2011-01-12 18:48:28 -05:00
return identity ;
}
2011-02-03 01:32:29 -05:00
// Check to see if this is a "next gen" identity.
2011-02-06 17:09:48 -05:00
if ( identityString . charAt ( 0 ) = = IDENTITY_VERSION_1 . charAt ( 0 ) & & identityString . length ( ) > 2 ) {
2011-01-12 18:48:28 -05:00
Uri . Builder builder = new Uri . Builder ( ) ;
builder . encodedQuery ( identityString . substring ( 1 ) ) ; // Need to cut off the ! at the beginning.
Uri uri = builder . build ( ) ;
2011-02-06 17:09:48 -05:00
for ( IdentityField key : IdentityField . values ( ) ) {
2011-01-12 18:48:28 -05:00
String value = uri . getQueryParameter ( key . value ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( value ! = null ) {
2011-01-12 18:48:28 -05:00
identity . put ( key , value ) ;
}
2008-11-01 17:32:06 -04:00
}
2011-01-12 18:48:28 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Decoded identity: " + identity . toString ( ) ) ;
// Sanity check our Integers so that recipients of this result don't have to.
2011-02-06 17:09:48 -05:00
for ( IdentityField key : IdentityField . getIntegerFields ( ) ) {
if ( identity . get ( key ) ! = null ) {
try {
2011-01-12 18:48:28 -05:00
Integer . parseInt ( identity . get ( key ) ) ;
2011-02-06 17:09:48 -05:00
} catch ( NumberFormatException e ) {
2011-01-12 18:48:28 -05:00
Log . e ( K9 . LOG_TAG , " Invalid " + key . name ( ) + " field in identity: " + identity . get ( key ) ) ;
}
}
}
2011-02-06 17:09:48 -05:00
} else {
2011-01-12 18:48:28 -05:00
// Legacy identity
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Got a saved legacy identity: " + identityString ) ;
StringTokenizer tokens = new StringTokenizer ( identityString , " : " , false ) ;
// First item is the body length. We use this to separate the composed reply from the quoted text.
2011-02-06 17:09:48 -05:00
if ( tokens . hasMoreTokens ( ) ) {
2011-01-12 18:48:28 -05:00
String bodyLengthS = Utility . base64Decode ( tokens . nextToken ( ) ) ;
2011-02-06 17:09:48 -05:00
try {
2011-01-12 18:48:28 -05:00
identity . put ( IdentityField . LENGTH , Integer . valueOf ( bodyLengthS ) . toString ( ) ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2011-01-12 18:48:28 -05:00
Log . e ( K9 . LOG_TAG , " Unable to parse bodyLength ' " + bodyLengthS + " ' " ) ;
}
}
2011-02-06 17:09:48 -05:00
if ( tokens . hasMoreTokens ( ) ) {
2011-01-12 18:48:28 -05:00
identity . put ( IdentityField . SIGNATURE , Utility . base64Decode ( tokens . nextToken ( ) ) ) ;
}
2011-02-06 17:09:48 -05:00
if ( tokens . hasMoreTokens ( ) ) {
2011-01-12 18:48:28 -05:00
identity . put ( IdentityField . NAME , Utility . base64Decode ( tokens . nextToken ( ) ) ) ;
}
2011-02-06 17:09:48 -05:00
if ( tokens . hasMoreTokens ( ) ) {
2011-01-12 18:48:28 -05:00
identity . put ( IdentityField . EMAIL , Utility . base64Decode ( tokens . nextToken ( ) ) ) ;
}
2011-05-10 11:54:17 -04:00
if ( tokens . hasMoreTokens ( ) ) {
identity . put ( IdentityField . QUOTED_TEXT_MODE , Utility . base64Decode ( tokens . nextToken ( ) ) ) ;
}
2008-11-01 17:32:06 -04:00
}
2011-01-12 18:48:28 -05:00
return identity ;
2008-11-01 17:32:06 -04:00
}
2011-01-12 18:48:28 -05:00
2012-01-22 00:25:06 -05:00
private String appendSignature ( String originalText ) {
String text = originalText ;
2011-02-06 17:09:48 -05:00
if ( mIdentity . getSignatureUse ( ) ) {
2013-10-08 19:14:08 -04:00
String signature = mSignatureView . getCharacters ( ) ;
2010-02-08 12:47:00 -05:00
2011-02-06 17:09:48 -05:00
if ( signature ! = null & & ! signature . contentEquals ( " " ) ) {
2013-10-08 17:07:21 -04:00
text + = " \ r \ n " + signature ;
2010-02-08 12:47:00 -05:00
}
2009-05-13 20:03:19 -04:00
}
2008-11-01 17:32:06 -04:00
2009-06-08 23:11:35 -04:00
return text ;
}
2008-11-01 17:32:06 -04:00
2011-11-14 17:23:29 -05:00
/ * *
* Get an HTML version of the signature in the # mSignatureView , if any .
* @return HTML version of signature .
* /
2011-11-14 16:16:19 -05:00
private String getSignatureHtml ( ) {
String signature = " " ;
if ( mIdentity . getSignatureUse ( ) ) {
2013-10-08 19:14:08 -04:00
signature = mSignatureView . getCharacters ( ) ;
2011-11-14 17:23:29 -05:00
if ( ! StringUtils . isNullOrEmpty ( signature ) ) {
2013-10-08 17:07:21 -04:00
signature = HtmlConverter . textToHtmlFragment ( " \ r \ n " + signature ) ;
2011-11-14 16:16:19 -05:00
}
}
return signature ;
}
2010-07-21 23:40:14 -04:00
2011-02-06 17:09:48 -05:00
private void sendMessage ( ) {
2010-07-21 23:40:22 -04:00
new SendMessageTask ( ) . execute ( ) ;
2010-07-21 23:40:14 -04:00
}
2012-09-13 22:08:17 -04:00
2011-02-06 17:09:48 -05:00
private void saveMessage ( ) {
2010-07-21 23:40:22 -04:00
new SaveMessageTask ( ) . execute ( ) ;
2008-11-01 17:32:06 -04:00
}
2011-02-06 17:09:48 -05:00
private void saveIfNeeded ( ) {
2011-11-19 19:05:24 -05:00
if ( ! mDraftNeedsSaving | | mPreventDraftSaving | | mPgpData . hasEncryptionKeys ( ) | |
2012-04-11 03:19:18 -04:00
mEncryptCheckbox . isChecked ( ) | | ! mAccount . hasDraftsFolder ( ) ) {
2008-11-01 17:32:06 -04:00
return ;
}
2010-07-27 08:10:09 -04:00
mDraftNeedsSaving = false ;
2012-01-20 17:15:11 -05:00
saveMessage ( ) ;
2010-07-27 08:10:09 -04:00
}
2011-02-06 17:09:48 -05:00
public void onEncryptionKeySelectionDone ( ) {
if ( mPgpData . hasEncryptionKeys ( ) ) {
2010-07-27 08:10:09 -04:00
onSend ( ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-07-27 08:10:09 -04:00
Toast . makeText ( this , R . string . send_aborted , Toast . LENGTH_SHORT ) . show ( ) ;
}
}
2011-02-06 17:09:48 -05:00
public void onEncryptDone ( ) {
if ( mPgpData . getEncryptedData ( ) ! = null ) {
2010-07-27 08:10:09 -04:00
onSend ( ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-07-27 08:10:09 -04:00
Toast . makeText ( this , R . string . send_aborted , Toast . LENGTH_SHORT ) . show ( ) ;
}
2008-11-01 17:32:06 -04:00
}
2011-02-06 17:09:48 -05:00
private void onSend ( ) {
if ( getAddresses ( mToView ) . length = = 0 & & getAddresses ( mCcView ) . length = = 0 & & getAddresses ( mBccView ) . length = = 0 ) {
2008-11-01 17:32:06 -04:00
mToView . setError ( getString ( R . string . message_compose_error_no_recipients ) ) ;
r62972@17h: jesse | 2009-05-07 10:49:32 -0400
First stab at a folderlist that doesn't know or care about messages
r62973@17h: jesse | 2009-05-07 10:50:11 -0400
A very broken first stab at a message list that only knows about one folder.
r62974@17h: jesse | 2009-05-07 10:50:44 -0400
When you go from an account list to an individual account, open a folderlist, not an fml
r62975@17h: jesse | 2009-05-07 10:51:24 -0400
Update Welcome activity to open an ml instead of an fml
r62976@17h: jesse | 2009-05-07 10:51:59 -0400
When setting up accounts is over, open an fl instead of an fml
r62977@17h: jesse | 2009-05-07 10:52:51 -0400
Update MessageView to use folderinfoholders and messageinfoholders from the 'correct' classes.
r62978@17h: jesse | 2009-05-07 10:59:07 -0400
MailService now notifies the fl instead of the fml. Not sure if it should also notify the ml. - will require testing
r62979@17h: jesse | 2009-05-07 11:01:09 -0400
Switch MessagingController's notifications from notifying the FML to notifying an ML
r62980@17h: jesse | 2009-05-07 11:25:22 -0400
Update AndroidManifest to know about the new world order
r62981@17h: jesse | 2009-05-07 11:26:11 -0400
Try to follow the android sdk docs for intent creation
r62982@17h: jesse | 2009-05-07 11:28:30 -0400
reset MessageList for another try at the conversion
r62983@17h: jesse | 2009-05-07 11:47:33 -0400
This version doesn't crash and has a working 'folder' layer. now to clean up the message list layer
r62984@17h: jesse | 2009-05-07 15:18:04 -0400
move step 1
r62985@17h: jesse | 2009-05-07 15:18:37 -0400
move step 1
r62986@17h: jesse | 2009-05-07 15:22:47 -0400
rename step 1
r62987@17h: jesse | 2009-05-07 17:38:02 -0400
checkpoint to move
r62988@17h: jesse | 2009-05-07 17:40:01 -0400
checkpointing a state with a working folder list and a message list that doesn't explode
r62989@17h: jesse | 2009-05-07 17:40:26 -0400
Remove debugging cruft from Welcome
r62990@17h: jesse | 2009-05-07 22:00:12 -0400
Basic functionality works.
r62991@17h: jesse | 2009-05-08 04:19:52 -0400
added a tool to build a K-9 "Beta"
r62992@17h: jesse | 2009-05-08 04:20:03 -0400
remove a disused file
r62993@17h: jesse | 2009-05-09 06:07:02 -0400
upgrading build infrastructure for the 1.5 sdk
r62994@17h: jesse | 2009-05-09 06:22:02 -0400
further refine onOpenMessage, removing more folder assumptions
r62995@17h: jesse | 2009-05-09 20:07:20 -0400
Make the Welcome activity open the autoexpandfolder rather than INBOX
r62996@17h: jesse | 2009-05-09 20:14:10 -0400
MessageList now stores the Folder name it was working with across pause-reload
r62997@17h: jesse | 2009-05-09 20:14:26 -0400
Removing dead code from FolderList
r63060@17h: jesse | 2009-05-10 00:07:33 -0400
Replace the old message list refreshing code which cleared and rebuilt the list from scratch with code which updates or deletes existing messages.
Add "go back to folder list" code
r63061@17h: jesse | 2009-05-10 00:07:50 -0400
fix message list menus for new world order
r63062@17h: jesse | 2009-05-10 00:08:11 -0400
Remove message list options from folder list menus
r63063@17h: jesse | 2009-05-10 00:10:02 -0400
remove more message list options from the folder list
r63064@17h: jesse | 2009-05-10 00:10:19 -0400
fix build.xml for the new android world order
r63065@17h: jesse | 2009-05-10 00:39:23 -0400
reformatted in advance of bug tracing
r63066@17h: jesse | 2009-05-10 05:53:28 -0400
fix our 'close' behavior to not leave extra activities around
clean up more vestigal code
r63067@17h: jesse | 2009-05-10 18:44:25 -0400
Improve "back button / accounts" workflow from FolderList -> AccountList
r63068@17h: jesse | 2009-05-10 19:11:47 -0400
* Add required code for the 'k9beta' build
r63069@17h: jesse | 2009-05-10 19:12:05 -0400
Make the folder list white backgrounded.
r63070@17h: jesse | 2009-05-10 19:12:26 -0400
* Include our required libraries in build.xml
r63071@17h: jesse | 2009-05-10 19:13:07 -0400
Added directories for our built code and our generated code
r63072@17h: jesse | 2009-05-10 19:13:36 -0400
Added a "back" button image
r63073@17h: jesse | 2009-05-10 20:13:50 -0400
Switch next/prev buttons to triangles for I18N and eventual "more easy-to-hit buttons" win
r63074@17h: jesse | 2009-05-10 20:17:18 -0400
Tidy Accounts.java for some perf hacking.
r63081@17h: jesse | 2009-05-10 22:13:33 -0400
First pass reformatting of the MessagingController
r63082@17h: jesse | 2009-05-10 23:50:28 -0400
MessageList now correctly updates when a background sync happens
r63083@17h: jesse | 2009-05-10 23:50:53 -0400
Tidying FolderList
r63084@17h: jesse | 2009-05-10 23:51:09 -0400
tidy
r63085@17h: jesse | 2009-05-10 23:51:27 -0400
tidy
r63086@17h: jesse | 2009-05-11 00:17:06 -0400
Properly update unread counts in the FolderList after sync
r63087@17h: jesse | 2009-05-11 01:38:14 -0400
Minor refactoring for readability. replace a boolean with a constant.
r63090@17h: jesse | 2009-05-11 02:58:31 -0400
now that the foreground of message lists is light, we don't need the light messagebox
r63091@17h: jesse | 2009-05-11 17:15:02 -0400
Added a string for "back to folder list"
r63092@17h: jesse | 2009-05-11 17:15:24 -0400
Added a message list header with a back button
r63093@17h: jesse | 2009-05-11 17:15:54 -0400
Remove the "folder list" button from the options menu. no sense duplicating it
r63094@17h: jesse | 2009-05-11 17:17:06 -0400
Refactored views, adding our replacement scrollable header
r63184@17h: jesse | 2009-05-12 07:07:15 -0400
fix weird bug where message lists could show a header element for a child
r63185@17h: jesse | 2009-05-12 07:08:12 -0400
Add new-style headers to folder lists. reimplement "get folder by name" to not use a bloody for loop
r63211@17h: jesse | 2009-05-12 18:37:48 -0400
Restore the former glory of the "load more messages" widget. it still needs an overhaul
r63296@17h: jesse | 2009-05-12 23:23:21 -0400
Get the indeterminate progress bar to show up again when you click "get more messages"
r63297@17h: jesse | 2009-05-13 02:40:39 -0400
Fixed off-by-one errors in click and keybindings for messagelist
r63298@17h: jesse | 2009-05-13 06:04:01 -0400
Put the folder title in the name of the folderSettings popup
r63299@17h: jesse | 2009-05-13 06:04:49 -0400
Reformatting. Removing debug logging
r63300@17h: jesse | 2009-05-13 06:05:32 -0400
Fixing "wrong item selected" bugs in the FolderList
r63328@17h: jesse | 2009-05-13 13:20:00 -0400
Update MessageView for 1.5
r63329@17h: jesse | 2009-05-13 13:50:29 -0400
A couple fixes to "picking the right item"
Titles on the message context menu
r63330@17h: jesse | 2009-05-13 13:58:37 -0400
Added an "open" context menu item to the folder list
r63347@17h: jesse | 2009-05-13 18:00:02 -0400
Try to get folderlists to sort in a stable way, so they jump around less in the ui
r63349@17h: jesse | 2009-05-13 20:37:19 -0400
Switch to using non-message-passing based notifications for redisplay of message lists, cut down redisplay frequency to not overload the display
r63432@17h: jesse | 2009-05-16 13:38:49 -0400
Android 1.5 no longer gives us apache.commons.codec by default and apache.commons.logging by default. Import them so we have em.
There's probably something smarter to do here.
r63438@17h: jesse | 2009-05-16 14:12:06 -0400
removed dead code
r63439@17h: jesse | 2009-05-16 14:30:57 -0400
Minor tidy
r63440@17h: jesse | 2009-05-16 14:39:34 -0400
First pass implementation making MessageList streamy for faster startup
r63441@17h: jesse | 2009-05-16 21:57:41 -0400
There's no reason for the FolderList to list local messages
r63442@17h: jesse | 2009-05-16 21:58:57 -0400
Switch to actually refreshing the message list after each item is loaded
r63450@17h: jesse | 2009-05-16 22:34:18 -0400
Default to pulling items out of the LocalStore by date, descending. (since that's the uneditable default ordering)
This makes our messages come out of the store in the order the user should see them
r63451@17h: jesse | 2009-05-16 22:34:44 -0400
Set some new defaults for the FolderList
r63452@17h: jesse | 2009-05-16 22:35:43 -0400
set some new message list item defaults
r63456@17h: jesse | 2009-05-17 12:56:10 -0400
It's not clear that Pop and WebDav actually set us an InternalDate. I'd rather use that so that spam doesn't topsort. But I also want this to _work_
r63457@17h: jesse | 2009-05-17 12:56:47 -0400
actually check to make sure we have a message to remove before removing it.
r63458@17h: jesse | 2009-05-17 13:10:07 -0400
Flip "security type" to before the port number, since changing security type is the thing more users are likely to know/care about and resets port number
r63469@17h: jesse | 2009-05-17 18:42:39 -0400
Provisional fix for "see the FoldeRList twice" bug
r63471@17h: jesse | 2009-05-17 20:47:41 -0400
Remove title bar from the message view
r63544@17h: jesse | 2009-05-20 23:53:38 -0400
folderlist tidying before i dig into the jumpy ordering bug
r63545@17h: jesse | 2009-05-20 23:56:00 -0400
Killing dead variables
r63546@17h: jesse | 2009-05-21 00:58:36 -0400
make the whole title section clicky
r63556@17h: jesse | 2009-05-21 01:48:13 -0400
Fix where we go when someone deletes a message
r63558@17h: jesse | 2009-05-21 22:44:46 -0400
Working toward switchable themes
r63563@17h: jesse | 2009-05-21 23:53:09 -0400
Make the MessageList's colors actually just inherit from the theme, rather than hardcoding black
r63567@17h: jesse | 2009-05-22 10:14:13 -0400
Kill a now-redundant comment
r63571@17h: jesse | 2009-05-22 19:43:30 -0400
further theme-independence work
r63572@17h: jesse | 2009-05-22 19:55:23 -0400
gete -> get (typo fix)
r63573@17h: jesse | 2009-05-22 22:48:49 -0400
First cut of a global prefs system as well as a theme preference. not that it works yet
r63577@17h: jesse | 2009-05-24 14:49:52 -0400
Once a user has actually put in valid user credentials, start syncing mail and folders in the background instantly.
This gives us a much better "new startup" experience
r63578@17h: jesse | 2009-05-24 14:55:00 -0400
MessageList doesn't need FolderUpdateWorker
r63579@17h: jesse | 2009-05-24 17:57:15 -0400
Fix "get message by uid"
Switch to showing messages 10 by 10, rather than 1 by 1 for huge loadtime performance improvements
r63587@17h: jesse | 2009-05-24 19:19:56 -0400
Cut down LocalMessage creation to not generate a MessageId or date formatter.
r63589@17h: jesse | 2009-05-24 22:22:32 -0400
Switch to null-escaping email address boundaries, rather than a VERY expensive URL-encoding
r63590@17h: jesse | 2009-05-24 22:23:21 -0400
Clean up our "auto-refresh the list when adding messages after a sync"
r63593@17h: jesse | 2009-05-24 22:53:45 -0400
replace isDateToday with a "rolling 18 hour window" variant that's more likely to give the user a useful answer and is 30x faster.
r63595@17h: jesse | 2009-05-24 23:54:14 -0400
When instantiating messges from the LocalStore, there's no need to clear headers before setting them, nor is there a need to set a generated message id
r63596@17h: jesse | 2009-05-24 23:54:39 -0400
make an overridable setGeneratedMessageId
r63597@17h: jesse | 2009-05-24 23:54:55 -0400
Remove new lies from comments
r63598@17h: jesse | 2009-05-24 23:55:35 -0400
Replace insanely expensive message header "name" part quoting with something consistent and cheap that does its work on the way INTO the database
r63605@17h: jesse | 2009-05-25 17:28:24 -0400
bring back the 1.1 sdk build.xml
r63606@17h: jesse | 2009-05-25 22:32:11 -0400
Actually enable switchable themese and compilation on 1.1
r63692@17h: jesse | 2009-05-29 23:55:17 -0400
Switch back to having titles for folder and message lists.
Restore auto-open-folder functionality
r63694@17h: jesse | 2009-05-30 18:50:39 -0400
Remove several off-by-one errors introduced by yesterday's return to android titlebars
r63696@17h: jesse | 2009-05-30 23:45:03 -0400
use convertView properly for performance and memory imrpovement in FolderList and MessageList
r63698@17h: jesse | 2009-05-31 19:42:59 -0400
Switch to using background shading to indicate "not yet fetched"
r63701@17h: jesse | 2009-05-31 21:28:47 -0400
Remving code we don't actually need these bits of apache commons on 1.1
2009-05-31 21:35:05 -04:00
Toast . makeText ( this , getString ( R . string . message_compose_error_no_recipients ) , Toast . LENGTH_LONG ) . show ( ) ;
2008-11-01 17:32:06 -04:00
return ;
}
2013-09-24 21:46:11 -04:00
if ( mWaitingForAttachments ! = WaitingAction . NONE ) {
return ;
}
if ( mNumAttachmentsLoading > 0 ) {
mWaitingForAttachments = WaitingAction . SEND ;
showWaitingForAttachmentDialog ( ) ;
} else {
performSend ( ) ;
}
}
private void performSend ( ) {
2011-11-21 02:59:51 -05:00
final CryptoProvider crypto = mAccount . getCryptoProvider ( ) ;
2011-02-06 17:09:48 -05:00
if ( mEncryptCheckbox . isChecked ( ) & & ! mPgpData . hasEncryptionKeys ( ) ) {
2010-07-27 08:10:09 -04:00
// key selection before encryption
2011-11-01 00:56:32 -04:00
StringBuilder emails = new StringBuilder ( ) ;
2011-11-21 02:59:51 -05:00
for ( Address address : getRecipientAddresses ( ) ) {
if ( emails . length ( ) ! = 0 ) {
emails . append ( ',' ) ;
}
emails . append ( address . getAddress ( ) ) ;
if ( ! mContinueWithoutPublicKey & &
! crypto . hasPublicKeyForEmail ( this , address . getAddress ( ) ) ) {
showDialog ( DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY ) ;
return ;
2010-07-27 08:10:09 -04:00
}
}
2011-02-06 17:09:48 -05:00
if ( emails . length ( ) ! = 0 ) {
2011-11-01 00:56:32 -04:00
emails . append ( ',' ) ;
2010-07-27 08:10:09 -04:00
}
2011-11-01 00:56:32 -04:00
emails . append ( mIdentity . getEmail ( ) ) ;
2010-07-27 08:10:09 -04:00
mPreventDraftSaving = true ;
2011-11-21 02:59:51 -05:00
if ( ! crypto . selectEncryptionKeys ( MessageCompose . this , emails . toString ( ) , mPgpData ) ) {
2010-07-27 08:10:09 -04:00
mPreventDraftSaving = false ;
}
return ;
}
2011-02-06 17:09:48 -05:00
if ( mPgpData . hasEncryptionKeys ( ) | | mPgpData . hasSignatureKey ( ) ) {
if ( mPgpData . getEncryptedData ( ) = = null ) {
2011-01-12 18:48:28 -05:00
String text = buildText ( false ) . getText ( ) ;
2010-07-27 08:10:09 -04:00
mPreventDraftSaving = true ;
2011-11-21 02:59:51 -05:00
if ( ! crypto . encrypt ( this , text , mPgpData ) ) {
2010-07-27 08:10:09 -04:00
mPreventDraftSaving = false ;
}
return ;
}
}
2010-07-21 23:40:14 -04:00
sendMessage ( ) ;
2011-02-03 01:32:29 -05:00
2011-02-06 17:09:48 -05:00
if ( mMessageReference ! = null & & mMessageReference . flag ! = null ) {
2011-02-03 01:32:29 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Setting referenced message ( " + mMessageReference . folderName + " , " + mMessageReference . uid + " ) flag to " + mMessageReference . flag ) ;
final Account account = Preferences . getPreferences ( this ) . getAccount ( mMessageReference . accountUuid ) ;
final String folderName = mMessageReference . folderName ;
final String sourceMessageUid = mMessageReference . uid ;
2012-02-04 08:52:45 -05:00
MessagingController . getInstance ( getApplication ( ) ) . setFlag ( account , folderName , sourceMessageUid , mMessageReference . flag , true ) ;
2011-02-03 01:32:29 -05:00
}
2008-11-01 17:32:06 -04:00
mDraftNeedsSaving = false ;
finish ( ) ;
}
2011-02-06 17:09:48 -05:00
private void onDiscard ( ) {
2012-01-21 23:14:58 -05:00
if ( mDraftId ! = INVALID_DRAFT_ID ) {
MessagingController . getInstance ( getApplication ( ) ) . deleteDraft ( mAccount , mDraftId ) ;
mDraftId = INVALID_DRAFT_ID ;
2009-10-17 23:34:54 -04:00
}
2008-11-01 17:32:06 -04:00
mHandler . sendEmptyMessage ( MSG_DISCARDED_DRAFT ) ;
mDraftNeedsSaving = false ;
finish ( ) ;
}
2011-02-06 17:09:48 -05:00
private void onSave ( ) {
2013-09-24 21:46:11 -04:00
if ( mWaitingForAttachments ! = WaitingAction . NONE ) {
return ;
}
if ( mNumAttachmentsLoading > 0 ) {
mWaitingForAttachments = WaitingAction . SAVE ;
showWaitingForAttachmentDialog ( ) ;
} else {
2013-09-30 18:53:08 -04:00
performSave ( ) ;
2013-09-24 21:46:11 -04:00
}
}
private void performSave ( ) {
2008-11-01 17:32:06 -04:00
saveIfNeeded ( ) ;
finish ( ) ;
}
2011-02-06 17:09:48 -05:00
private void onAddCcBcc ( ) {
2011-03-22 03:06:11 -04:00
mCcWrapper . setVisibility ( View . VISIBLE ) ;
mBccWrapper . setVisibility ( View . VISIBLE ) ;
2012-09-13 22:26:57 -04:00
computeAddCcBccVisibility ( ) ;
}
/ * *
* Hide the ' Add Cc / Bcc ' menu item when both fields are visible .
* /
private void computeAddCcBccVisibility ( ) {
if ( mMenu ! = null & & mCcWrapper . getVisibility ( ) = = View . VISIBLE & &
mBccWrapper . getVisibility ( ) = = View . VISIBLE ) {
2012-09-13 22:09:18 -04:00
mMenu . findItem ( R . id . add_cc_bcc ) . setVisible ( false ) ;
}
2008-11-01 17:32:06 -04:00
}
2011-08-27 20:42:27 -04:00
private void onReadReceipt ( ) {
CharSequence txt ;
if ( mReadReceipt = = false ) {
2011-11-14 16:58:01 -05:00
txt = getString ( R . string . read_receipt_enabled ) ;
2011-08-27 20:42:27 -04:00
mReadReceipt = true ;
} else {
2011-11-14 16:58:01 -05:00
txt = getString ( R . string . read_receipt_disabled ) ;
2011-08-27 20:42:27 -04:00
mReadReceipt = false ;
}
Context context = getApplicationContext ( ) ;
Toast toast = Toast . makeText ( context , txt , Toast . LENGTH_SHORT ) ;
toast . show ( ) ;
}
2012-09-13 22:08:17 -04:00
2008-11-01 17:32:06 -04:00
/ * *
* Kick off a picker for whatever kind of MIME types we ' ll accept and let Android take over .
* /
2011-02-06 17:09:48 -05:00
private void onAddAttachment ( ) {
if ( K9 . isGalleryBuggy ( ) ) {
if ( K9 . useGalleryBugWorkaround ( ) ) {
2010-05-02 14:24:33 -04:00
Toast . makeText ( MessageCompose . this ,
2010-05-11 22:51:59 -04:00
getString ( R . string . message_compose_use_workaround ) ,
Toast . LENGTH_LONG ) . show ( ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-05-02 14:24:33 -04:00
Toast . makeText ( MessageCompose . this ,
2010-05-11 22:51:59 -04:00
getString ( R . string . message_compose_buggy_gallery ) ,
Toast . LENGTH_LONG ) . show ( ) ;
2010-05-02 14:24:33 -04:00
}
}
2010-11-13 21:27:42 -05:00
onAddAttachment2 ( " */* " ) ;
2010-05-02 14:24:33 -04:00
}
/ * *
* Kick off a picker for the specified MIME type and let Android take over .
2012-01-22 00:25:06 -05:00
*
* @param mime_type
* The MIME type we want our attachment to have .
2010-05-02 14:24:33 -04:00
* /
2011-02-06 17:09:48 -05:00
private void onAddAttachment2 ( final String mime_type ) {
if ( mAccount . getCryptoProvider ( ) . isAvailable ( this ) ) {
2010-07-27 08:10:09 -04:00
Toast . makeText ( this , R . string . attachment_encryption_unsupported , Toast . LENGTH_LONG ) . show ( ) ;
}
2008-11-01 17:32:06 -04:00
Intent i = new Intent ( Intent . ACTION_GET_CONTENT ) ;
2014-01-26 11:02:08 -05:00
i . putExtra ( Intent . EXTRA_ALLOW_MULTIPLE , true ) ;
2008-11-01 17:32:06 -04:00
i . addCategory ( Intent . CATEGORY_OPENABLE ) ;
2010-05-02 14:24:33 -04:00
i . setType ( mime_type ) ;
2012-01-22 00:25:06 -05:00
mIgnoreOnPause = true ;
2008-11-01 17:32:06 -04:00
startActivityForResult ( Intent . createChooser ( i , null ) , ACTIVITY_REQUEST_PICK_ATTACHMENT ) ;
}
2011-02-06 17:09:48 -05:00
private void addAttachment ( Uri uri ) {
2010-11-13 21:27:42 -05:00
addAttachment ( uri , null ) ;
2008-11-01 17:32:06 -04:00
}
2011-02-06 17:09:48 -05:00
private void addAttachment ( Uri uri , String contentType ) {
2013-08-14 12:05:57 -04:00
Attachment attachment = new Attachment ( ) ;
attachment . state = Attachment . LoadingState . URI_ONLY ;
attachment . uri = uri ;
attachment . contentType = contentType ;
attachment . loaderId = + + mMaxLoaderId ;
addAttachmentView ( attachment ) ;
initAttachmentInfoLoader ( attachment ) ;
}
private void initAttachmentInfoLoader ( Attachment attachment ) {
LoaderManager loaderManager = getSupportLoaderManager ( ) ;
Bundle bundle = new Bundle ( ) ;
bundle . putParcelable ( LOADER_ARG_ATTACHMENT , attachment ) ;
loaderManager . initLoader ( attachment . loaderId , bundle , mAttachmentInfoLoaderCallback ) ;
}
private void initAttachmentContentLoader ( Attachment attachment ) {
LoaderManager loaderManager = getSupportLoaderManager ( ) ;
Bundle bundle = new Bundle ( ) ;
bundle . putParcelable ( LOADER_ARG_ATTACHMENT , attachment ) ;
loaderManager . initLoader ( attachment . loaderId , bundle , mAttachmentContentLoaderCallback ) ;
}
private void addAttachmentView ( Attachment attachment ) {
boolean hasMetadata = ( attachment . state ! = Attachment . LoadingState . URI_ONLY ) ;
boolean isLoadingComplete = ( attachment . state = = Attachment . LoadingState . COMPLETE ) ;
View view = getLayoutInflater ( ) . inflate ( R . layout . message_compose_attachment , mAttachments , false ) ;
TextView nameView = ( TextView ) view . findViewById ( R . id . attachment_name ) ;
View progressBar = view . findViewById ( R . id . progressBar ) ;
if ( hasMetadata ) {
nameView . setText ( attachment . name ) ;
} else {
nameView . setText ( R . string . loading_attachment ) ;
}
progressBar . setVisibility ( isLoadingComplete ? View . GONE : View . VISIBLE ) ;
ImageButton delete = ( ImageButton ) view . findViewById ( R . id . attachment_delete ) ;
delete . setOnClickListener ( MessageCompose . this ) ;
delete . setTag ( view ) ;
view . setTag ( attachment ) ;
mAttachments . addView ( view ) ;
}
private View getAttachmentView ( int loaderId ) {
for ( int i = 0 , childCount = mAttachments . getChildCount ( ) ; i < childCount ; i + + ) {
View view = mAttachments . getChildAt ( i ) ;
Attachment tag = ( Attachment ) view . getTag ( ) ;
if ( tag ! = null & & tag . loaderId = = loaderId ) {
return view ;
2010-11-13 21:27:42 -05:00
}
2008-11-01 17:32:06 -04:00
}
2013-08-14 12:05:57 -04:00
return null ;
}
private LoaderManager . LoaderCallbacks < Attachment > mAttachmentInfoLoaderCallback =
new LoaderManager . LoaderCallbacks < Attachment > ( ) {
@Override
public Loader < Attachment > onCreateLoader ( int id , Bundle args ) {
2013-09-24 21:46:11 -04:00
onFetchAttachmentStarted ( ) ;
2013-08-14 12:05:57 -04:00
Attachment attachment = args . getParcelable ( LOADER_ARG_ATTACHMENT ) ;
return new AttachmentInfoLoader ( MessageCompose . this , attachment ) ;
2008-11-01 17:32:06 -04:00
}
2013-08-14 12:05:57 -04:00
@Override
public void onLoadFinished ( Loader < Attachment > loader , Attachment attachment ) {
int loaderId = loader . getId ( ) ;
View view = getAttachmentView ( loaderId ) ;
if ( view ! = null ) {
view . setTag ( attachment ) ;
TextView nameView = ( TextView ) view . findViewById ( R . id . attachment_name ) ;
nameView . setText ( attachment . name ) ;
attachment . loaderId = + + mMaxLoaderId ;
initAttachmentContentLoader ( attachment ) ;
2013-09-24 21:46:11 -04:00
} else {
onFetchAttachmentFinished ( ) ;
2013-08-14 12:05:57 -04:00
}
getSupportLoaderManager ( ) . destroyLoader ( loaderId ) ;
}
@Override
public void onLoaderReset ( Loader < Attachment > loader ) {
2013-09-24 21:46:11 -04:00
onFetchAttachmentFinished ( ) ;
2010-11-13 21:27:42 -05:00
}
2013-08-14 12:05:57 -04:00
} ;
private LoaderManager . LoaderCallbacks < Attachment > mAttachmentContentLoaderCallback =
new LoaderManager . LoaderCallbacks < Attachment > ( ) {
@Override
public Loader < Attachment > onCreateLoader ( int id , Bundle args ) {
Attachment attachment = args . getParcelable ( LOADER_ARG_ATTACHMENT ) ;
return new AttachmentContentLoader ( MessageCompose . this , attachment ) ;
2009-11-16 15:51:34 -05:00
}
2013-08-14 12:05:57 -04:00
@Override
public void onLoadFinished ( Loader < Attachment > loader , Attachment attachment ) {
int loaderId = loader . getId ( ) ;
View view = getAttachmentView ( loaderId ) ;
if ( view ! = null ) {
if ( attachment . state = = Attachment . LoadingState . COMPLETE ) {
view . setTag ( attachment ) ;
View progressBar = view . findViewById ( R . id . progressBar ) ;
progressBar . setVisibility ( View . GONE ) ;
} else {
mAttachments . removeView ( view ) ;
}
2010-01-28 01:25:10 -05:00
}
2013-08-14 12:05:57 -04:00
2013-09-24 21:46:11 -04:00
onFetchAttachmentFinished ( ) ;
2013-08-14 12:05:57 -04:00
getSupportLoaderManager ( ) . destroyLoader ( loaderId ) ;
2010-01-28 01:25:10 -05:00
}
2013-08-14 12:05:57 -04:00
@Override
public void onLoaderReset ( Loader < Attachment > loader ) {
2013-09-24 21:46:11 -04:00
onFetchAttachmentFinished ( ) ;
2013-08-14 12:05:57 -04:00
}
} ;
2010-10-05 02:03:51 -04:00
2013-09-24 21:46:11 -04:00
private void onFetchAttachmentStarted ( ) {
mNumAttachmentsLoading + = 1 ;
}
private void onFetchAttachmentFinished ( ) {
// We're not allowed to perform fragment transactions when called from onLoadFinished().
// So we use the Handler to call performStalledAction().
mHandler . sendEmptyMessage ( MSG_PERFORM_STALLED_ACTION ) ;
}
private void performStalledAction ( ) {
mNumAttachmentsLoading - = 1 ;
WaitingAction waitingFor = mWaitingForAttachments ;
mWaitingForAttachments = WaitingAction . NONE ;
if ( waitingFor ! = WaitingAction . NONE ) {
dismissWaitingForAttachmentDialog ( ) ;
}
switch ( waitingFor ) {
case SEND : {
performSend ( ) ;
break ;
}
case SAVE : {
performSave ( ) ;
break ;
}
2013-09-25 09:20:43 -04:00
case NONE :
break ;
2013-09-24 21:46:11 -04:00
}
2008-11-01 17:32:06 -04:00
}
@Override
2011-02-06 17:09:48 -05:00
protected void onActivityResult ( int requestCode , int resultCode , Intent data ) {
2010-07-27 08:10:09 -04:00
// if a CryptoSystem activity is returning, then mPreventDraftSaving was set to true
mPreventDraftSaving = false ;
2011-02-06 17:09:48 -05:00
if ( mAccount . getCryptoProvider ( ) . onActivityResult ( this , requestCode , resultCode , data , mPgpData ) ) {
2010-07-27 08:10:09 -04:00
return ;
}
2009-11-21 17:45:39 -05:00
if ( resultCode ! = RESULT_OK )
return ;
2011-02-06 17:09:48 -05:00
if ( data = = null ) {
2008-11-01 17:32:06 -04:00
return ;
}
2011-02-06 17:09:48 -05:00
switch ( requestCode ) {
case ACTIVITY_REQUEST_PICK_ATTACHMENT :
2014-01-26 11:02:08 -05:00
addAttachmentsFromResultIntent ( data ) ;
2011-02-06 17:09:48 -05:00
mDraftNeedsSaving = true ;
break ;
2011-03-22 03:06:11 -04:00
case CONTACT_PICKER_TO :
case CONTACT_PICKER_CC :
case CONTACT_PICKER_BCC :
2012-04-08 19:04:59 -04:00
ContactItem contact = mContacts . extractInfoFromContactPickerIntent ( data ) ;
2012-04-08 12:32:04 -04:00
if ( contact = = null ) {
2011-03-22 03:06:11 -04:00
Toast . makeText ( this , getString ( R . string . error_contact_address_not_found ) , Toast . LENGTH_LONG ) . show ( ) ;
return ;
}
2012-04-08 19:14:51 -04:00
if ( contact . emailAddresses . size ( ) > 1 ) {
2011-10-01 13:16:35 -04:00
Intent i = new Intent ( this , EmailAddressList . class ) ;
2012-04-08 19:23:45 -04:00
i . putExtra ( EmailAddressList . EXTRA_CONTACT_ITEM , contact ) ;
2012-04-08 12:29:08 -04:00
if ( requestCode = = CONTACT_PICKER_TO ) {
startActivityForResult ( i , CONTACT_PICKER_TO2 ) ;
} else if ( requestCode = = CONTACT_PICKER_CC ) {
startActivityForResult ( i , CONTACT_PICKER_CC2 ) ;
} else if ( requestCode = = CONTACT_PICKER_BCC ) {
startActivityForResult ( i , CONTACT_PICKER_BCC2 ) ;
}
return ;
}
if ( K9 . DEBUG ) {
2012-04-08 19:14:51 -04:00
List < String > emails = contact . emailAddresses ;
2012-04-08 12:32:04 -04:00
for ( int i = 0 ; i < emails . size ( ) ; i + + ) {
Log . v ( K9 . LOG_TAG , " email[ " + i + " ]: " + emails . get ( i ) ) ;
2012-04-08 12:29:08 -04:00
}
}
2012-04-08 19:14:51 -04:00
String email = contact . emailAddresses . get ( 0 ) ;
2011-03-22 03:06:11 -04:00
if ( requestCode = = CONTACT_PICKER_TO ) {
2012-04-08 12:32:04 -04:00
addAddress ( mToView , new Address ( email , " " ) ) ;
2011-03-22 03:06:11 -04:00
} else if ( requestCode = = CONTACT_PICKER_CC ) {
2012-04-08 12:32:04 -04:00
addAddress ( mCcView , new Address ( email , " " ) ) ;
2011-03-22 03:06:11 -04:00
} else if ( requestCode = = CONTACT_PICKER_BCC ) {
2012-04-08 12:32:04 -04:00
addAddress ( mBccView , new Address ( email , " " ) ) ;
2011-03-22 03:06:11 -04:00
} else {
return ;
}
2011-02-06 17:09:48 -05:00
break ;
2012-04-08 12:29:08 -04:00
case CONTACT_PICKER_TO2 :
case CONTACT_PICKER_CC2 :
case CONTACT_PICKER_BCC2 :
2012-04-10 22:47:10 -04:00
String emailAddr = data . getStringExtra ( EmailAddressList . EXTRA_EMAIL_ADDRESS ) ;
2012-04-08 12:29:08 -04:00
if ( requestCode = = CONTACT_PICKER_TO2 ) {
addAddress ( mToView , new Address ( emailAddr , " " ) ) ;
} else if ( requestCode = = CONTACT_PICKER_CC2 ) {
addAddress ( mCcView , new Address ( emailAddr , " " ) ) ;
} else if ( requestCode = = CONTACT_PICKER_BCC2 ) {
addAddress ( mBccView , new Address ( emailAddr , " " ) ) ;
}
2012-04-10 22:47:10 -04:00
break ;
2009-11-21 17:45:39 -05:00
}
2009-06-08 23:11:35 -04:00
}
2014-01-26 11:02:08 -05:00
@TargetApi ( Build . VERSION_CODES . JELLY_BEAN )
private void addAttachmentsFromResultIntent ( Intent data ) {
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . KITKAT ) {
ClipData clipData = data . getClipData ( ) ;
if ( clipData ! = null ) {
for ( int i = 0 , end = clipData . getItemCount ( ) ; i < end ; i + + ) {
Uri uri = clipData . getItemAt ( i ) . getUri ( ) ;
if ( uri ! = null ) {
addAttachment ( uri ) ;
}
}
return ;
}
}
Uri uri = data . getData ( ) ;
if ( uri ! = null ) {
addAttachment ( uri ) ;
}
}
2011-03-22 03:06:11 -04:00
public void doLaunchContactPicker ( int resultId ) {
2012-01-22 00:25:06 -05:00
mIgnoreOnPause = true ;
2011-03-22 03:06:11 -04:00
startActivityForResult ( mContacts . contactPickerIntent ( ) , resultId ) ;
}
2012-03-22 17:17:10 -04:00
private void onAccountChosen ( Account account , Identity identity ) {
2011-02-06 17:09:48 -05:00
if ( ! mAccount . equals ( account ) ) {
if ( K9 . DEBUG ) {
2010-07-21 23:15:28 -04:00
Log . v ( K9 . LOG_TAG , " Switching account from " + mAccount + " to " + account ) ;
}
// on draft edit, make sure we don't keep previous message UID
2012-05-19 21:13:58 -04:00
if ( mAction = = Action . EDIT_DRAFT ) {
2010-07-21 23:15:28 -04:00
mMessageReference = null ;
}
// test whether there is something to save
2012-01-21 23:14:58 -05:00
if ( mDraftNeedsSaving | | ( mDraftId ! = INVALID_DRAFT_ID ) ) {
final long previousDraftId = mDraftId ;
2010-07-21 23:15:28 -04:00
final Account previousAccount = mAccount ;
// make current message appear as new
2012-01-21 23:14:58 -05:00
mDraftId = INVALID_DRAFT_ID ;
2010-07-21 23:15:28 -04:00
// actual account switch
mAccount = account ;
2011-02-06 17:09:48 -05:00
if ( K9 . DEBUG ) {
2010-07-21 23:15:28 -04:00
Log . v ( K9 . LOG_TAG , " Account switch, saving new draft in new account " ) ;
}
2010-07-21 23:40:14 -04:00
saveMessage ( ) ;
2010-07-21 23:15:28 -04:00
2012-01-21 23:14:58 -05:00
if ( previousDraftId ! = INVALID_DRAFT_ID ) {
2011-02-06 17:09:48 -05:00
if ( K9 . DEBUG ) {
2010-07-21 23:15:28 -04:00
Log . v ( K9 . LOG_TAG , " Account switch, deleting draft from previous account: "
2012-01-21 23:14:58 -05:00
+ previousDraftId ) ;
2010-07-21 23:15:28 -04:00
}
MessagingController . getInstance ( getApplication ( ) ) . deleteDraft ( previousAccount ,
2012-01-21 23:14:58 -05:00
previousDraftId ) ;
2010-07-21 23:15:28 -04:00
}
2011-02-06 17:09:48 -05:00
} else {
2010-07-21 23:15:28 -04:00
mAccount = account ;
}
2012-08-09 21:38:10 -04:00
// Show CC/BCC text input field when switching to an account that always wants them
// displayed.
// Please note that we're not hiding the fields if the user switches back to an account
// that doesn't have this setting checked.
if ( mAccount . isAlwaysShowCcBcc ( ) ) {
onAddCcBcc ( ) ;
}
2010-07-21 23:15:28 -04:00
// not sure how to handle mFolder, mSourceMessage?
}
switchToIdentity ( identity ) ;
}
2011-02-06 17:09:48 -05:00
private void switchToIdentity ( Identity identity ) {
2009-08-29 18:40:52 -04:00
mIdentity = identity ;
mIdentityChanged = true ;
mDraftNeedsSaving = true ;
updateFrom ( ) ;
2012-02-18 10:26:28 -05:00
updateBcc ( ) ;
2009-11-21 17:45:39 -05:00
updateSignature ( ) ;
2012-05-20 16:44:32 -04:00
updateMessageFormat ( ) ;
2009-06-08 23:11:35 -04:00
}
2009-11-21 17:45:39 -05:00
2011-02-06 17:09:48 -05:00
private void updateFrom ( ) {
2012-03-23 21:34:29 -04:00
mChooseIdentityButton . setText ( mIdentity . getEmail ( ) ) ;
2009-06-08 23:11:35 -04:00
}
2009-11-21 17:45:39 -05:00
2012-02-18 10:26:28 -05:00
private void updateBcc ( ) {
if ( mIdentityChanged ) {
mBccWrapper . setVisibility ( View . VISIBLE ) ;
}
mBccView . setText ( " " ) ;
addAddresses ( mBccView , mAccount . getAlwaysBcc ( ) ) ;
}
2011-02-06 17:09:48 -05:00
private void updateSignature ( ) {
if ( mIdentity . getSignatureUse ( ) ) {
2013-10-08 19:14:08 -04:00
mSignatureView . setCharacters ( mIdentity . getSignature ( ) ) ;
2010-02-08 12:47:00 -05:00
mSignatureView . setVisibility ( View . VISIBLE ) ;
2011-02-06 17:09:48 -05:00
} else {
2010-02-08 12:47:00 -05:00
mSignatureView . setVisibility ( View . GONE ) ;
}
2008-11-01 17:32:06 -04:00
}
2012-01-22 00:25:06 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void onClick ( View view ) {
switch ( view . getId ( ) ) {
case R . id . attachment_delete :
/ *
* The view is the delete button , and we have previously set the tag of
* the delete button to the view that owns it . We don ' t use parent because the
* view is very complex and could change in the future .
* /
mAttachments . removeView ( ( View ) view . getTag ( ) ) ;
mDraftNeedsSaving = true ;
break ;
2011-05-10 11:54:17 -04:00
case R . id . quoted_text_show :
showOrHideQuotedText ( QuotedTextMode . SHOW ) ;
2012-05-20 16:44:32 -04:00
updateMessageFormat ( ) ;
2011-05-10 11:54:17 -04:00
mDraftNeedsSaving = true ;
break ;
2011-02-06 17:09:48 -05:00
case R . id . quoted_text_delete :
2011-05-10 11:54:17 -04:00
showOrHideQuotedText ( QuotedTextMode . HIDE ) ;
2012-05-20 16:44:32 -04:00
updateMessageFormat ( ) ;
2011-02-06 17:09:48 -05:00
mDraftNeedsSaving = true ;
break ;
case R . id . quoted_text_edit :
2012-05-20 16:44:32 -04:00
mForcePlainText = true ;
2011-02-06 17:09:48 -05:00
if ( mMessageReference ! = null ) { // shouldn't happen...
// TODO - Should we check if mSourceMessageBody is already present and bypass the MessagingController call?
MessagingController . getInstance ( getApplication ( ) ) . addListener ( mListener ) ;
final Account account = Preferences . getPreferences ( this ) . getAccount ( mMessageReference . accountUuid ) ;
final String folderName = mMessageReference . folderName ;
final String sourceMessageUid = mMessageReference . uid ;
MessagingController . getInstance ( getApplication ( ) ) . loadMessageForView ( account , folderName , sourceMessageUid , null ) ;
}
break ;
2012-03-22 17:17:10 -04:00
case R . id . identity :
showDialog ( DIALOG_CHOOSE_IDENTITY ) ;
break ;
2011-02-05 18:14:02 -05:00
}
}
2012-05-20 16:44:32 -04:00
/ * *
* Show or hide the quoted text .
*
* @param mode
* The value to set { @link # mQuotedTextMode } to .
2011-02-05 18:14:02 -05:00
* /
2011-05-10 11:54:17 -04:00
private void showOrHideQuotedText ( QuotedTextMode mode ) {
mQuotedTextMode = mode ;
2012-05-20 16:44:32 -04:00
switch ( mode ) {
case NONE :
case HIDE : {
if ( mode = = QuotedTextMode . NONE ) {
mQuotedTextShow . setVisibility ( View . GONE ) ;
} else {
mQuotedTextShow . setVisibility ( View . VISIBLE ) ;
}
mQuotedTextBar . setVisibility ( View . GONE ) ;
2011-05-10 11:54:17 -04:00
mQuotedText . setVisibility ( View . GONE ) ;
mQuotedHTML . setVisibility ( View . GONE ) ;
mQuotedTextEdit . setVisibility ( View . GONE ) ;
2012-05-20 16:44:32 -04:00
break ;
2011-05-10 11:54:17 -04:00
}
2012-05-20 16:44:32 -04:00
case SHOW : {
mQuotedTextShow . setVisibility ( View . GONE ) ;
mQuotedTextBar . setVisibility ( View . VISIBLE ) ;
2011-05-10 11:54:17 -04:00
2012-05-20 16:44:32 -04:00
if ( mQuotedTextFormat = = SimpleMessageFormat . HTML ) {
mQuotedText . setVisibility ( View . GONE ) ;
mQuotedHTML . setVisibility ( View . VISIBLE ) ;
mQuotedTextEdit . setVisibility ( View . VISIBLE ) ;
} else {
mQuotedText . setVisibility ( View . VISIBLE ) ;
mQuotedHTML . setVisibility ( View . GONE ) ;
mQuotedTextEdit . setVisibility ( View . GONE ) ;
}
break ;
}
2008-11-01 17:32:06 -04:00
}
}
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public boolean onOptionsItemSelected ( MenuItem item ) {
switch ( item . getItemId ( ) ) {
case R . id . send :
mPgpData . setEncryptionKeys ( null ) ;
onSend ( ) ;
break ;
case R . id . save :
2011-11-19 19:05:24 -05:00
if ( mEncryptCheckbox . isChecked ( ) ) {
showDialog ( DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED ) ;
} else {
onSave ( ) ;
}
2011-02-06 17:09:48 -05:00
break ;
case R . id . discard :
onDiscard ( ) ;
break ;
case R . id . add_cc_bcc :
onAddCcBcc ( ) ;
break ;
case R . id . add_attachment :
onAddAttachment ( ) ;
break ;
case R . id . add_attachment_image :
onAddAttachment2 ( " image/* " ) ;
break ;
case R . id . add_attachment_video :
onAddAttachment2 ( " video/* " ) ;
break ;
2011-08-27 20:42:27 -04:00
case R . id . read_receipt :
onReadReceipt ( ) ;
2011-02-06 17:09:48 -05:00
default :
return super . onOptionsItemSelected ( item ) ;
2008-11-01 17:32:06 -04:00
}
return true ;
}
2010-04-16 08:20:10 -04:00
@Override
2011-02-06 17:09:48 -05:00
public boolean onCreateOptionsMenu ( Menu menu ) {
2008-11-01 17:32:06 -04:00
super . onCreateOptionsMenu ( menu ) ;
2012-07-12 12:29:41 -04:00
getSupportMenuInflater ( ) . inflate ( R . menu . message_compose_option , menu ) ;
2009-11-21 17:45:39 -05:00
2012-08-24 11:23:03 -04:00
mMenu = menu ;
2012-01-20 17:15:11 -05:00
// Disable the 'Save' menu option if Drafts folder is set to -NONE-
2012-04-11 03:19:18 -04:00
if ( ! mAccount . hasDraftsFolder ( ) ) {
2012-01-20 12:02:35 -05:00
menu . findItem ( R . id . save ) . setEnabled ( false ) ;
2012-01-20 14:10:11 -05:00
}
2012-01-20 12:02:35 -05:00
2010-05-02 14:24:33 -04:00
/ *
* Show the menu items " Add attachment (Image) " and " Add attachment (Video) "
2010-05-11 22:51:59 -04:00
* if the work - around for the Gallery bug is enabled ( see Issue 1186 ) .
2010-05-02 14:24:33 -04:00
* /
2012-08-09 20:31:55 -04:00
menu . findItem ( R . id . add_attachment_image ) . setVisible ( K9 . useGalleryBugWorkaround ( ) ) ;
menu . findItem ( R . id . add_attachment_video ) . setVisible ( K9 . useGalleryBugWorkaround ( ) ) ;
return true ;
}
2010-05-02 14:24:33 -04:00
2012-08-09 20:31:55 -04:00
@Override
public boolean onPrepareOptionsMenu ( Menu menu ) {
super . onPrepareOptionsMenu ( menu ) ;
2012-09-13 22:26:57 -04:00
computeAddCcBccVisibility ( ) ;
2010-05-02 14:24:33 -04:00
2008-11-01 17:32:06 -04:00
return true ;
}
2010-07-28 19:17:46 -04:00
@Override
2011-02-06 17:09:48 -05:00
public void onBackPressed ( ) {
2012-02-02 16:56:56 -05:00
if ( mDraftNeedsSaving ) {
if ( mEncryptCheckbox . isChecked ( ) ) {
showDialog ( DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED ) ;
2012-04-11 03:19:18 -04:00
} else if ( ! mAccount . hasDraftsFolder ( ) ) {
2012-02-02 16:56:56 -05:00
showDialog ( DIALOG_CONFIRM_DISCARD_ON_BACK ) ;
} else {
showDialog ( DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE ) ;
}
2012-01-20 17:15:11 -05:00
} else {
2012-02-02 16:56:56 -05:00
// Check if editing an existing draft.
if ( mDraftId = = INVALID_DRAFT_ID ) {
onDiscard ( ) ;
} else {
super . onBackPressed ( ) ;
}
2012-01-20 17:15:11 -05:00
}
2012-01-20 12:02:35 -05:00
}
2013-09-24 21:46:11 -04:00
private void showWaitingForAttachmentDialog ( ) {
String title ;
switch ( mWaitingForAttachments ) {
case SEND : {
title = getString ( R . string . fetching_attachment_dialog_title_send ) ;
break ;
}
case SAVE : {
title = getString ( R . string . fetching_attachment_dialog_title_save ) ;
break ;
}
default : {
return ;
}
}
ProgressDialogFragment fragment = ProgressDialogFragment . newInstance ( title ,
getString ( R . string . fetching_attachment_dialog_message ) ) ;
fragment . show ( getSupportFragmentManager ( ) , FRAGMENT_WAITING_FOR_ATTACHMENT ) ;
}
public void onCancel ( ProgressDialogFragment fragment ) {
attachmentProgressDialogCancelled ( ) ;
}
void attachmentProgressDialogCancelled ( ) {
mWaitingForAttachments = WaitingAction . NONE ;
}
private void dismissWaitingForAttachmentDialog ( ) {
ProgressDialogFragment fragment = ( ProgressDialogFragment )
getSupportFragmentManager ( ) . findFragmentByTag ( FRAGMENT_WAITING_FOR_ATTACHMENT ) ;
if ( fragment ! = null ) {
fragment . dismiss ( ) ;
}
}
2010-07-04 13:46:55 -04:00
@Override
2011-02-06 17:09:48 -05:00
public Dialog onCreateDialog ( int id ) {
switch ( id ) {
case DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE :
return new AlertDialog . Builder ( this )
. setTitle ( R . string . save_or_discard_draft_message_dlg_title )
. setMessage ( R . string . save_or_discard_draft_message_instructions_fmt )
. setPositiveButton ( R . string . save_draft_action , new DialogInterface . OnClickListener ( ) {
2012-01-22 00:25:06 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void onClick ( DialogInterface dialog , int whichButton ) {
dismissDialog ( DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE ) ;
onSave ( ) ;
}
} )
. setNegativeButton ( R . string . discard_action , new DialogInterface . OnClickListener ( ) {
2012-01-22 00:25:06 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void onClick ( DialogInterface dialog , int whichButton ) {
dismissDialog ( DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE ) ;
onDiscard ( ) ;
}
} )
. create ( ) ;
2011-11-19 19:05:24 -05:00
case DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED :
return new AlertDialog . Builder ( this )
. setTitle ( R . string . refuse_to_save_draft_marked_encrypted_dlg_title )
. setMessage ( R . string . refuse_to_save_draft_marked_encrypted_instructions_fmt )
. setNeutralButton ( R . string . okay_action , new DialogInterface . OnClickListener ( ) {
2012-01-22 00:25:06 -05:00
@Override
2011-11-19 19:05:24 -05:00
public void onClick ( DialogInterface dialog , int whichButton ) {
dismissDialog ( DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED ) ;
}
} )
. create ( ) ;
2011-11-21 02:59:51 -05:00
case DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY :
return new AlertDialog . Builder ( this )
. setTitle ( R . string . continue_without_public_key_dlg_title )
. setMessage ( R . string . continue_without_public_key_instructions_fmt )
. setPositiveButton ( R . string . continue_action , new DialogInterface . OnClickListener ( ) {
2012-01-22 00:25:06 -05:00
@Override
2011-11-21 02:59:51 -05:00
public void onClick ( DialogInterface dialog , int whichButton ) {
dismissDialog ( DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY ) ;
mContinueWithoutPublicKey = true ;
onSend ( ) ;
}
} )
. setNegativeButton ( R . string . back_action , new DialogInterface . OnClickListener ( ) {
2012-01-22 00:25:06 -05:00
@Override
2011-11-21 02:59:51 -05:00
public void onClick ( DialogInterface dialog , int whichButton ) {
dismissDialog ( DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY ) ;
mContinueWithoutPublicKey = false ;
}
} )
. create ( ) ;
2012-02-02 16:56:56 -05:00
case DIALOG_CONFIRM_DISCARD_ON_BACK :
return new AlertDialog . Builder ( this )
. setTitle ( R . string . confirm_discard_draft_message_title )
. setMessage ( R . string . confirm_discard_draft_message )
. setPositiveButton ( R . string . cancel_action , new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int whichButton ) {
dismissDialog ( DIALOG_CONFIRM_DISCARD_ON_BACK ) ;
}
} )
. setNegativeButton ( R . string . discard_action , new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int whichButton ) {
dismissDialog ( DIALOG_CONFIRM_DISCARD_ON_BACK ) ;
Toast . makeText ( MessageCompose . this ,
getString ( R . string . message_discarded_toast ) ,
Toast . LENGTH_LONG ) . show ( ) ;
onDiscard ( ) ;
}
} )
. create ( ) ;
2012-03-22 17:17:10 -04:00
case DIALOG_CHOOSE_IDENTITY :
2012-09-15 21:16:29 -04:00
Context context = new ContextThemeWrapper ( this ,
2013-02-06 14:08:57 -05:00
( K9 . getK9Theme ( ) = = K9 . Theme . LIGHT ) ?
2012-09-15 21:24:40 -04:00
R . style . Theme_K9_Dialog_Light :
R . style . Theme_K9_Dialog_Dark ) ;
2012-04-02 21:41:44 -04:00
Builder builder = new AlertDialog . Builder ( context ) ;
2012-03-22 17:17:10 -04:00
builder . setTitle ( R . string . send_as ) ;
2012-09-15 21:16:29 -04:00
final IdentityAdapter adapter = new IdentityAdapter ( context ) ;
2012-03-22 17:17:10 -04:00
builder . setAdapter ( adapter , new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
IdentityContainer container = ( IdentityContainer ) adapter . getItem ( which ) ;
onAccountChosen ( container . account , container . identity ) ;
}
} ) ;
return builder . create ( ) ;
2010-07-04 13:46:55 -04:00
}
return super . onCreateDialog ( id ) ;
}
2008-11-01 17:32:06 -04:00
/ * *
2012-01-22 00:25:06 -05:00
* Add all attachments of an existing message as if they were added by hand .
*
* @param part
* The message part to check for being an attachment . This method will recurse if it ' s
* a multipart part .
* @param depth
* The recursion depth . Currently unused .
*
* @return { @code true } if all attachments were able to be attached , { @code false } otherwise .
*
* @throws MessagingException
* In case of an error
2008-11-01 17:32:06 -04:00
* /
2011-02-06 17:09:48 -05:00
private boolean loadAttachments ( Part part , int depth ) throws MessagingException {
if ( part . getBody ( ) instanceof Multipart ) {
2008-11-01 17:32:06 -04:00
Multipart mp = ( Multipart ) part . getBody ( ) ;
boolean ret = true ;
2011-02-06 17:09:48 -05:00
for ( int i = 0 , count = mp . getCount ( ) ; i < count ; i + + ) {
if ( ! loadAttachments ( mp . getBodyPart ( i ) , depth + 1 ) ) {
2008-11-01 17:32:06 -04:00
ret = false ;
}
}
return ret ;
2012-01-22 00:25:06 -05:00
}
String contentType = MimeUtility . unfoldAndDecode ( part . getContentType ( ) ) ;
String name = MimeUtility . getHeaderParameter ( contentType , " name " ) ;
if ( name ! = null ) {
Body body = part . getBody ( ) ;
if ( body ! = null & & body instanceof LocalAttachmentBody ) {
final Uri uri = ( ( LocalAttachmentBody ) body ) . getContentUri ( ) ;
mHandler . post ( new Runnable ( ) {
@Override
public void run ( ) {
addAttachment ( uri ) ;
}
} ) ;
} else {
return false ;
2008-11-01 17:32:06 -04:00
}
}
2012-01-22 00:25:06 -05:00
return true ;
2008-11-01 17:32:06 -04:00
}
/ * *
* Pull out the parts of the now loaded source message and apply them to the new message
* depending on the type of message being composed .
2012-05-19 21:23:20 -04:00
*
* @param message
* The source message used to populate the various text fields .
2008-11-01 17:32:06 -04:00
* /
2011-02-06 17:09:48 -05:00
private void processSourceMessage ( Message message ) {
try {
2012-05-19 21:23:20 -04:00
switch ( mAction ) {
case REPLY :
case REPLY_ALL : {
processMessageToReplyTo ( message ) ;
break ;
2008-11-01 17:32:06 -04:00
}
2012-05-19 21:23:20 -04:00
case FORWARD : {
processMessageToForward ( message ) ;
break ;
2008-11-01 17:32:06 -04:00
}
2012-05-19 21:23:20 -04:00
case EDIT_DRAFT : {
processDraftMessage ( message ) ;
break ;
}
default : {
Log . w ( K9 . LOG_TAG , " processSourceMessage() called with unsupported action " ) ;
break ;
2010-12-01 01:04:12 -05:00
}
2012-05-19 21:23:20 -04:00
}
} catch ( MessagingException me ) {
/ * *
* Let the user continue composing their message even if we have a problem processing
* the source message . Log it as an error , though .
* /
Log . e ( K9 . LOG_TAG , " Error while processing source message: " , me ) ;
} finally {
mSourceMessageProcessed = true ;
mDraftNeedsSaving = false ;
}
2012-05-20 16:44:32 -04:00
updateMessageFormat ( ) ;
2012-05-19 21:23:20 -04:00
}
private void processMessageToReplyTo ( Message message ) throws MessagingException {
if ( message . getSubject ( ) ! = null ) {
final String subject = PREFIX . matcher ( message . getSubject ( ) ) . replaceFirst ( " " ) ;
2010-12-01 01:04:12 -05:00
2012-05-19 21:23:20 -04:00
if ( ! subject . toLowerCase ( Locale . US ) . startsWith ( " re: " ) ) {
mSubjectView . setText ( " Re: " + subject ) ;
} else {
mSubjectView . setText ( subject ) ;
}
} else {
mSubjectView . setText ( " " ) ;
}
2010-12-01 01:04:12 -05:00
2012-05-19 21:23:20 -04:00
/ *
* If a reply - to was included with the message use that , otherwise use the from
* or sender address .
* /
Address [ ] replyToAddresses ;
if ( message . getReplyTo ( ) . length > 0 ) {
replyToAddresses = message . getReplyTo ( ) ;
} else {
replyToAddresses = message . getFrom ( ) ;
}
2010-12-01 01:04:12 -05:00
2012-05-19 21:23:20 -04:00
// if we're replying to a message we sent, we probably meant
// to reply to the recipient of that message
if ( mAccount . isAnIdentity ( replyToAddresses ) ) {
replyToAddresses = message . getRecipients ( RecipientType . TO ) ;
}
2010-12-01 01:04:12 -05:00
2012-05-19 21:23:20 -04:00
addAddresses ( mToView , replyToAddresses ) ;
2009-11-21 17:45:39 -05:00
2009-11-17 16:13:29 -05:00
2012-05-19 21:23:20 -04:00
if ( message . getMessageId ( ) ! = null & & message . getMessageId ( ) . length ( ) > 0 ) {
mInReplyTo = message . getMessageId ( ) ;
2009-11-21 17:45:39 -05:00
2014-02-15 16:05:18 -05:00
String [ ] refs = message . getReferences ( ) ;
if ( refs ! = null & & refs . length > 0 ) {
mReferences = TextUtils . join ( " " , refs ) + " " + mInReplyTo ;
2012-05-19 21:23:20 -04:00
} else {
mReferences = mInReplyTo ;
}
} else {
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " could not get Message-ID. " ) ;
}
// Quote the message and setup the UI.
populateUIWithQuotedMessage ( mAccount . isDefaultQuotedTextShown ( ) ) ;
if ( mAction = = Action . REPLY | | mAction = = Action . REPLY_ALL ) {
Identity useIdentity = null ;
for ( Address address : message . getRecipients ( RecipientType . TO ) ) {
Identity identity = mAccount . findIdentity ( address ) ;
if ( identity ! = null ) {
useIdentity = identity ;
break ;
}
}
if ( useIdentity = = null ) {
if ( message . getRecipients ( RecipientType . CC ) . length > 0 ) {
for ( Address address : message . getRecipients ( RecipientType . CC ) ) {
2010-03-03 23:00:30 -05:00
Identity identity = mAccount . findIdentity ( address ) ;
2011-02-06 17:09:48 -05:00
if ( identity ! = null ) {
2009-08-29 18:40:52 -04:00
useIdentity = identity ;
break ;
}
}
}
2012-05-19 21:23:20 -04:00
}
if ( useIdentity ! = null ) {
Identity defaultIdentity = mAccount . getIdentity ( 0 ) ;
if ( useIdentity ! = defaultIdentity ) {
switchToIdentity ( useIdentity ) ;
}
}
}
2009-11-21 17:45:39 -05:00
2012-05-19 21:23:20 -04:00
if ( mAction = = Action . REPLY_ALL ) {
if ( message . getReplyTo ( ) . length > 0 ) {
for ( Address address : message . getFrom ( ) ) {
2014-02-22 18:30:53 -05:00
if ( ! mAccount . isAnIdentity ( address ) & & ! Utility . arrayContains ( replyToAddresses , address ) ) {
2012-05-19 21:23:20 -04:00
addAddress ( mToView , address ) ;
2012-03-05 16:17:31 -05:00
}
2012-05-19 21:23:20 -04:00
}
}
for ( Address address : message . getRecipients ( RecipientType . TO ) ) {
if ( ! mAccount . isAnIdentity ( address ) & & ! Utility . arrayContains ( replyToAddresses , address ) ) {
addAddress ( mToView , address ) ;
}
2009-11-21 17:45:39 -05:00
2012-05-19 21:23:20 -04:00
}
if ( message . getRecipients ( RecipientType . CC ) . length > 0 ) {
for ( Address address : message . getRecipients ( RecipientType . CC ) ) {
if ( ! mAccount . isAnIdentity ( address ) & & ! Utility . arrayContains ( replyToAddresses , address ) ) {
addAddress ( mCcView , address ) ;
2008-11-01 17:32:06 -04:00
}
2009-11-21 17:45:39 -05:00
2008-11-01 17:32:06 -04:00
}
2012-05-19 21:23:20 -04:00
mCcWrapper . setVisibility ( View . VISIBLE ) ;
}
}
}
2010-10-05 02:04:16 -04:00
2012-05-19 21:23:20 -04:00
private void processMessageToForward ( Message message ) throws MessagingException {
String subject = message . getSubject ( ) ;
if ( subject ! = null & & ! subject . toLowerCase ( Locale . US ) . startsWith ( " fwd: " ) ) {
mSubjectView . setText ( " Fwd: " + subject ) ;
} else {
mSubjectView . setText ( subject ) ;
}
mQuoteStyle = QuoteStyle . HEADER ;
2010-10-05 02:04:16 -04:00
2012-09-07 14:02:30 -04:00
// "Be Like Thunderbird" - on forwarded messages, set the message ID
// of the forwarded message in the references and the reply to. TB
// only includes ID of the message being forwarded in the reference,
// even if there are multiple references.
if ( ! StringUtils . isNullOrEmpty ( message . getMessageId ( ) ) ) {
mInReplyTo = message . getMessageId ( ) ;
mReferences = mInReplyTo ;
} else {
if ( K9 . DEBUG ) {
Log . d ( K9 . LOG_TAG , " could not get Message-ID. " ) ;
}
}
2012-05-19 21:23:20 -04:00
// Quote the message and setup the UI.
populateUIWithQuotedMessage ( true ) ;
2011-05-10 11:54:17 -04:00
2012-05-19 21:23:20 -04:00
if ( ! mSourceMessageProcessed ) {
if ( ! loadAttachments ( message , 0 ) ) {
mHandler . sendEmptyMessage ( MSG_SKIPPED_ATTACHMENTS ) ;
}
}
}
2011-01-10 21:49:00 -05:00
2012-05-19 21:23:20 -04:00
private void processDraftMessage ( Message message ) throws MessagingException {
String showQuotedTextMode = " NONE " ;
2009-11-21 17:45:39 -05:00
2012-05-19 21:23:20 -04:00
mDraftId = MessagingController . getInstance ( getApplication ( ) ) . getId ( message ) ;
mSubjectView . setText ( message . getSubject ( ) ) ;
addAddresses ( mToView , message . getRecipients ( RecipientType . TO ) ) ;
if ( message . getRecipients ( RecipientType . CC ) . length > 0 ) {
addAddresses ( mCcView , message . getRecipients ( RecipientType . CC ) ) ;
mCcWrapper . setVisibility ( View . VISIBLE ) ;
}
2010-06-02 12:29:59 -04:00
2012-05-19 21:23:20 -04:00
Address [ ] bccRecipients = message . getRecipients ( RecipientType . BCC ) ;
if ( bccRecipients . length > 0 ) {
addAddresses ( mBccView , bccRecipients ) ;
String bccAddress = mAccount . getAlwaysBcc ( ) ;
if ( bccRecipients . length = = 1 & & bccAddress ! = null & & bccAddress . equals ( bccRecipients [ 0 ] . toString ( ) ) ) {
// If the auto-bcc is the only entry in the BCC list, don't show the Bcc fields.
mBccWrapper . setVisibility ( View . GONE ) ;
} else {
mBccWrapper . setVisibility ( View . VISIBLE ) ;
}
}
2010-06-02 12:29:59 -04:00
2012-05-19 21:23:20 -04:00
// Read In-Reply-To header from draft
final String [ ] inReplyTo = message . getHeader ( " In-Reply-To " ) ;
if ( ( inReplyTo ! = null ) & & ( inReplyTo . length > = 1 ) ) {
mInReplyTo = inReplyTo [ 0 ] ;
}
2011-01-12 18:48:28 -05:00
2012-05-19 21:23:20 -04:00
// Read References header from draft
final String [ ] references = message . getHeader ( " References " ) ;
if ( ( references ! = null ) & & ( references . length > = 1 ) ) {
mReferences = references [ 0 ] ;
}
2011-01-12 18:48:28 -05:00
2012-05-19 21:23:20 -04:00
if ( ! mSourceMessageProcessed ) {
loadAttachments ( message , 0 ) ;
}
2011-01-12 18:48:28 -05:00
2012-05-19 21:23:20 -04:00
// Decode the identity header when loading a draft.
// See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
Map < IdentityField , String > k9identity = new HashMap < IdentityField , String > ( ) ;
if ( message . getHeader ( K9 . IDENTITY_HEADER ) ! = null & & message . getHeader ( K9 . IDENTITY_HEADER ) . length > 0 & & message . getHeader ( K9 . IDENTITY_HEADER ) [ 0 ] ! = null ) {
k9identity = parseIdentityHeader ( message . getHeader ( K9 . IDENTITY_HEADER ) [ 0 ] ) ;
}
2009-11-21 17:45:39 -05:00
2012-05-19 21:23:20 -04:00
Identity newIdentity = new Identity ( ) ;
if ( k9identity . containsKey ( IdentityField . SIGNATURE ) ) {
newIdentity . setSignatureUse ( true ) ;
newIdentity . setSignature ( k9identity . get ( IdentityField . SIGNATURE ) ) ;
mSignatureChanged = true ;
} else {
newIdentity . setSignatureUse ( message . getFolder ( ) . getAccount ( ) . getSignatureUse ( ) ) ;
newIdentity . setSignature ( mIdentity . getSignature ( ) ) ;
}
2011-01-12 18:48:28 -05:00
2012-05-19 21:23:20 -04:00
if ( k9identity . containsKey ( IdentityField . NAME ) ) {
newIdentity . setName ( k9identity . get ( IdentityField . NAME ) ) ;
mIdentityChanged = true ;
} else {
newIdentity . setName ( mIdentity . getName ( ) ) ;
}
2011-02-03 01:32:29 -05:00
2012-05-19 21:23:20 -04:00
if ( k9identity . containsKey ( IdentityField . EMAIL ) ) {
newIdentity . setEmail ( k9identity . get ( IdentityField . EMAIL ) ) ;
mIdentityChanged = true ;
} else {
newIdentity . setEmail ( mIdentity . getEmail ( ) ) ;
}
2011-05-10 18:23:25 -04:00
2012-05-19 21:23:20 -04:00
if ( k9identity . containsKey ( IdentityField . ORIGINAL_MESSAGE ) ) {
mMessageReference = null ;
try {
String originalMessage = k9identity . get ( IdentityField . ORIGINAL_MESSAGE ) ;
MessageReference messageReference = new MessageReference ( originalMessage ) ;
// Check if this is a valid account in our database
Preferences prefs = Preferences . getPreferences ( getApplicationContext ( ) ) ;
Account account = prefs . getAccount ( messageReference . accountUuid ) ;
if ( account ! = null ) {
mMessageReference = messageReference ;
2011-05-10 11:54:17 -04:00
}
2012-05-19 21:23:20 -04:00
} catch ( MessagingException e ) {
Log . e ( K9 . LOG_TAG , " Could not decode message reference in identity. " , e ) ;
}
}
2011-05-10 11:54:17 -04:00
2012-05-19 21:23:20 -04:00
int cursorPosition = 0 ;
if ( k9identity . containsKey ( IdentityField . CURSOR_POSITION ) ) {
try {
cursorPosition = Integer . valueOf ( k9identity . get ( IdentityField . CURSOR_POSITION ) ) . intValue ( ) ;
} catch ( Exception e ) {
Log . e ( K9 . LOG_TAG , " Could not parse cursor position for MessageCompose; continuing. " , e ) ;
}
}
2011-06-01 16:03:56 -04:00
2012-05-19 21:23:20 -04:00
if ( k9identity . containsKey ( IdentityField . QUOTED_TEXT_MODE ) ) {
showQuotedTextMode = k9identity . get ( IdentityField . QUOTED_TEXT_MODE ) ;
}
2011-05-10 11:54:17 -04:00
2012-05-19 21:23:20 -04:00
mIdentity = newIdentity ;
2011-01-12 18:48:28 -05:00
2012-05-19 21:23:20 -04:00
updateSignature ( ) ;
updateFrom ( ) ;
2011-05-10 18:23:25 -04:00
2012-05-19 21:23:20 -04:00
Integer bodyLength = k9identity . get ( IdentityField . LENGTH ) ! = null
? Integer . valueOf ( k9identity . get ( IdentityField . LENGTH ) )
: 0 ;
Integer bodyOffset = k9identity . get ( IdentityField . OFFSET ) ! = null
? Integer . valueOf ( k9identity . get ( IdentityField . OFFSET ) )
: 0 ;
Integer bodyFooterOffset = k9identity . get ( IdentityField . FOOTER_OFFSET ) ! = null
? Integer . valueOf ( k9identity . get ( IdentityField . FOOTER_OFFSET ) )
: null ;
Integer bodyPlainLength = k9identity . get ( IdentityField . PLAIN_LENGTH ) ! = null
? Integer . valueOf ( k9identity . get ( IdentityField . PLAIN_LENGTH ) )
: null ;
Integer bodyPlainOffset = k9identity . get ( IdentityField . PLAIN_OFFSET ) ! = null
? Integer . valueOf ( k9identity . get ( IdentityField . PLAIN_OFFSET ) )
: null ;
mQuoteStyle = k9identity . get ( IdentityField . QUOTE_STYLE ) ! = null
? QuoteStyle . valueOf ( k9identity . get ( IdentityField . QUOTE_STYLE ) )
: mAccount . getQuoteStyle ( ) ;
2012-05-20 16:44:32 -04:00
QuotedTextMode quotedMode ;
try {
quotedMode = QuotedTextMode . valueOf ( showQuotedTextMode ) ;
} catch ( Exception e ) {
quotedMode = QuotedTextMode . NONE ;
}
2012-05-19 21:23:20 -04:00
// Always respect the user's current composition format preference, even if the
// draft was saved in a different format.
// TODO - The current implementation doesn't allow a user in HTML mode to edit a draft that wasn't saved with K9mail.
2012-05-20 16:44:32 -04:00
String messageFormatString = k9identity . get ( IdentityField . MESSAGE_FORMAT ) ;
MessageFormat messageFormat = null ;
if ( messageFormatString ! = null ) {
try {
messageFormat = MessageFormat . valueOf ( messageFormatString ) ;
} catch ( Exception e ) { /* do nothing */ }
}
2012-05-19 21:23:20 -04:00
if ( messageFormat = = null ) {
// This message probably wasn't created by us. The exception is legacy
// drafts created before the advent of HTML composition. In those cases,
// we'll display the whole message (including the quoted part) in the
// composition window. If that's the case, try and convert it to text to
// match the behavior in text mode.
2013-10-08 19:14:08 -04:00
mMessageContentView . setCharacters ( getBodyTextFromMessage ( message , SimpleMessageFormat . TEXT ) ) ;
2012-05-20 16:44:32 -04:00
mForcePlainText = true ;
showOrHideQuotedText ( quotedMode ) ;
2012-05-19 21:23:20 -04:00
return ;
}
2012-05-20 16:44:32 -04:00
if ( messageFormat = = MessageFormat . HTML ) {
2012-05-19 21:23:20 -04:00
Part part = MimeUtility . findFirstPartByMimeType ( message , " text/html " ) ;
if ( part ! = null ) { // Shouldn't happen if we were the one who saved it.
2012-05-20 16:44:32 -04:00
mQuotedTextFormat = SimpleMessageFormat . HTML ;
2012-05-19 21:23:20 -04:00
String text = MimeUtility . getTextFromPart ( part ) ;
if ( K9 . DEBUG ) {
Log . d ( K9 . LOG_TAG , " Loading message with offset " + bodyOffset + " , length " + bodyLength + " . Text length is " + text . length ( ) + " . " ) ;
2011-05-10 18:23:25 -04:00
}
2011-05-10 11:54:17 -04:00
2013-10-08 19:15:43 -04:00
if ( bodyOffset + bodyLength > text . length ( ) ) {
// The draft was edited outside of K-9 Mail?
Log . d ( K9 . LOG_TAG , " The identity field from the draft contains an invalid LENGTH/OFFSET " ) ;
bodyOffset = 0 ;
bodyLength = 0 ;
}
2012-05-19 21:23:20 -04:00
// Grab our reply text.
String bodyText = text . substring ( bodyOffset , bodyOffset + bodyLength ) ;
2013-10-08 19:14:08 -04:00
mMessageContentView . setCharacters ( HtmlConverter . htmlToText ( bodyText ) ) ;
2012-05-19 21:23:20 -04:00
// Regenerate the quoted html without our user content in it.
StringBuilder quotedHTML = new StringBuilder ( ) ;
quotedHTML . append ( text . substring ( 0 , bodyOffset ) ) ; // stuff before the reply
quotedHTML . append ( text . substring ( bodyOffset + bodyLength ) ) ;
if ( quotedHTML . length ( ) > 0 ) {
mQuotedHtmlContent = new InsertableHtmlContent ( ) ;
mQuotedHtmlContent . setQuotedContent ( quotedHTML ) ;
// We don't know if bodyOffset refers to the header or to the footer
mQuotedHtmlContent . setHeaderInsertionPoint ( bodyOffset ) ;
if ( bodyFooterOffset ! = null ) {
mQuotedHtmlContent . setFooterInsertionPoint ( bodyFooterOffset ) ;
} else {
mQuotedHtmlContent . setFooterInsertionPoint ( bodyOffset ) ;
}
2013-03-01 11:26:52 -05:00
mQuotedHTML . setText ( mQuotedHtmlContent . getQuotedContent ( ) ) ;
2012-05-19 21:23:20 -04:00
}
2009-11-24 19:40:29 -05:00
}
2012-05-19 21:23:20 -04:00
if ( bodyPlainOffset ! = null & & bodyPlainLength ! = null ) {
processSourceMessageText ( message , bodyPlainOffset , bodyPlainLength , false ) ;
}
2012-05-20 16:44:32 -04:00
} else if ( messageFormat = = MessageFormat . TEXT ) {
mQuotedTextFormat = SimpleMessageFormat . TEXT ;
2012-05-19 21:23:20 -04:00
processSourceMessageText ( message , bodyOffset , bodyLength , true ) ;
} else {
Log . e ( K9 . LOG_TAG , " Unhandled message format. " ) ;
2011-05-10 11:54:17 -04:00
}
2012-05-19 21:23:20 -04:00
// Set the cursor position if we have it.
try {
mMessageContentView . setSelection ( cursorPosition ) ;
} catch ( Exception e ) {
Log . e ( K9 . LOG_TAG , " Could not set cursor position in MessageCompose; ignoring. " , e ) ;
}
2012-05-20 16:44:32 -04:00
showOrHideQuotedText ( quotedMode ) ;
2008-11-01 17:32:06 -04:00
}
2013-10-08 17:07:21 -04:00
/ * *
2011-11-14 16:16:19 -05:00
* Pull out the parts of the now loaded source message and apply them to the new message
* depending on the type of message being composed .
* @param message Source message
* @param bodyOffset Insertion point for reply .
* @param bodyLength Length of reply .
* @param viewMessageContent Update mMessageContentView or not .
* @throws MessagingException
* /
private void processSourceMessageText ( Message message , Integer bodyOffset , Integer bodyLength ,
boolean viewMessageContent ) throws MessagingException {
Part textPart = MimeUtility . findFirstPartByMimeType ( message , " text/plain " ) ;
if ( textPart ! = null ) {
String text = MimeUtility . getTextFromPart ( textPart ) ;
if ( K9 . DEBUG ) {
Log . d ( K9 . LOG_TAG , " Loading message with offset " + bodyOffset + " , length " + bodyLength + " . Text length is " + text . length ( ) + " . " ) ;
}
// If we had a body length (and it was valid), separate the composition from the quoted text
// and put them in their respective places in the UI.
2013-10-08 18:30:21 -04:00
if ( bodyLength > 0 ) {
try {
String bodyText = text . substring ( bodyOffset , bodyOffset + bodyLength ) ;
// Regenerate the quoted text without our user content in it nor added newlines.
StringBuilder quotedText = new StringBuilder ( ) ;
if ( bodyOffset = = 0 & & text . substring ( bodyLength , bodyLength + 4 ) . equals ( " \ r \ n \ r \ n " ) ) {
// top-posting: ignore two newlines at start of quote
quotedText . append ( text . substring ( bodyLength + 4 ) ) ;
} else if ( bodyOffset + bodyLength = = text . length ( ) & &
text . substring ( bodyOffset - 2 , bodyOffset ) . equals ( " \ r \ n " ) ) {
// bottom-posting: ignore newline at end of quote
quotedText . append ( text . substring ( 0 , bodyOffset - 2 ) ) ;
} else {
quotedText . append ( text . substring ( 0 , bodyOffset ) ) ; // stuff before the reply
quotedText . append ( text . substring ( bodyOffset + bodyLength ) ) ;
}
2011-11-14 16:16:19 -05:00
2013-10-08 18:30:21 -04:00
if ( viewMessageContent ) {
mMessageContentView . setCharacters ( bodyText ) ;
}
2011-11-14 16:16:19 -05:00
2013-10-08 18:30:21 -04:00
mQuotedText . setCharacters ( quotedText ) ;
} catch ( IndexOutOfBoundsException e ) {
// Invalid bodyOffset or bodyLength. The draft was edited outside of K-9 Mail?
Log . d ( K9 . LOG_TAG , " The identity field from the draft contains an invalid bodyOffset/bodyLength " ) ;
if ( viewMessageContent ) {
mMessageContentView . setCharacters ( text ) ;
}
2013-10-08 19:14:08 -04:00
}
2013-10-08 18:30:21 -04:00
} else {
2013-10-08 19:14:08 -04:00
if ( viewMessageContent ) {
mMessageContentView . setCharacters ( text ) ;
}
2011-11-14 16:16:19 -05:00
}
}
}
2011-11-14 16:58:01 -05:00
// Regexes to check for signature.
private static final Pattern DASH_SIGNATURE_PLAIN = Pattern . compile ( " \ r \ n-- \ r \ n.* " , Pattern . DOTALL ) ;
private static final Pattern DASH_SIGNATURE_HTML = Pattern . compile ( " (<br( /)?>| \ r? \ n)-- <br( /)?> " , Pattern . CASE_INSENSITIVE ) ;
private static final Pattern BLOCKQUOTE_START = Pattern . compile ( " <blockquote " , Pattern . CASE_INSENSITIVE ) ;
private static final Pattern BLOCKQUOTE_END = Pattern . compile ( " </blockquote> " , Pattern . CASE_INSENSITIVE ) ;
2011-01-12 18:48:28 -05:00
/ * *
* Build and populate the UI with the quoted message .
2012-01-22 00:25:06 -05:00
*
* @param showQuotedText
* { @code true } if the quoted text should be shown , { @code false } otherwise .
*
2011-01-12 18:48:28 -05:00
* @throws MessagingException
* /
2012-01-22 00:25:06 -05:00
private void populateUIWithQuotedMessage ( boolean showQuotedText ) throws MessagingException {
2012-05-20 16:44:32 -04:00
MessageFormat origMessageFormat = mAccount . getMessageFormat ( ) ;
if ( mForcePlainText | | origMessageFormat = = MessageFormat . TEXT ) {
// Use plain text for the quoted message
mQuotedTextFormat = SimpleMessageFormat . TEXT ;
} else if ( origMessageFormat = = MessageFormat . AUTO ) {
// Figure out which message format to use for the quoted text by looking if the source
// message contains a text/html part. If it does, we use that.
mQuotedTextFormat =
( MimeUtility . findFirstPartByMimeType ( mSourceMessage , " text/html " ) = = null ) ?
SimpleMessageFormat . TEXT : SimpleMessageFormat . HTML ;
} else {
mQuotedTextFormat = SimpleMessageFormat . HTML ;
2011-11-14 18:28:45 -05:00
}
2011-01-12 18:48:28 -05:00
// TODO -- I am assuming that mSourceMessageBody will always be a text part. Is this a safe assumption?
// Handle the original message in the reply
// If we already have mSourceMessageBody, use that. It's pre-populated if we've got crypto going on.
2012-05-20 16:44:32 -04:00
String content = ( mSourceMessageBody ! = null ) ?
mSourceMessageBody :
getBodyTextFromMessage ( mSourceMessage , mQuotedTextFormat ) ;
if ( mQuotedTextFormat = = SimpleMessageFormat . HTML ) {
2011-11-14 16:58:01 -05:00
// Strip signature.
// closing tags such as </div>, </span>, </table>, </pre> will be cut off.
2012-05-19 21:13:58 -04:00
if ( mAccount . isStripSignature ( ) & &
( mAction = = Action . REPLY | | mAction = = Action . REPLY_ALL ) ) {
2011-11-14 16:58:01 -05:00
Matcher dashSignatureHtml = DASH_SIGNATURE_HTML . matcher ( content ) ;
if ( dashSignatureHtml . find ( ) ) {
Matcher blockquoteStart = BLOCKQUOTE_START . matcher ( content ) ;
Matcher blockquoteEnd = BLOCKQUOTE_END . matcher ( content ) ;
List < Integer > start = new ArrayList < Integer > ( ) ;
List < Integer > end = new ArrayList < Integer > ( ) ;
while ( blockquoteStart . find ( ) ) {
start . add ( blockquoteStart . start ( ) ) ;
}
while ( blockquoteEnd . find ( ) ) {
end . add ( blockquoteEnd . start ( ) ) ;
}
if ( start . size ( ) ! = end . size ( ) ) {
2012-01-09 19:47:23 -05:00
Log . d ( K9 . LOG_TAG , " There are " + start . size ( ) + " <blockquote> tags, but " +
2011-11-14 16:58:01 -05:00
end . size ( ) + " </blockquote> tags. Refusing to strip. " ) ;
} else if ( start . size ( ) > 0 ) {
// Ignore quoted signatures in blockquotes.
dashSignatureHtml . region ( 0 , start . get ( 0 ) ) ;
if ( dashSignatureHtml . find ( ) ) {
// before first <blockquote>.
content = content . substring ( 0 , dashSignatureHtml . start ( ) ) ;
} else {
for ( int i = 0 ; i < start . size ( ) - 1 ; i + + ) {
// within blockquotes.
if ( end . get ( i ) < start . get ( i + 1 ) ) {
dashSignatureHtml . region ( end . get ( i ) , start . get ( i + 1 ) ) ;
if ( dashSignatureHtml . find ( ) ) {
content = content . substring ( 0 , dashSignatureHtml . start ( ) ) ;
break ;
}
}
}
if ( end . get ( end . size ( ) - 1 ) < content . length ( ) ) {
// after last </blockquote>.
dashSignatureHtml . region ( end . get ( end . size ( ) - 1 ) , content . length ( ) ) ;
if ( dashSignatureHtml . find ( ) ) {
content = content . substring ( 0 , dashSignatureHtml . start ( ) ) ;
}
}
}
} else {
// No blockquotes found.
content = content . substring ( 0 , dashSignatureHtml . start ( ) ) ;
}
}
2012-01-09 19:47:23 -05:00
// Fix the stripping off of closing tags if a signature was stripped,
2011-11-14 16:58:01 -05:00
// as well as clean up the HTML of the quoted message.
HtmlCleaner cleaner = new HtmlCleaner ( ) ;
CleanerProperties properties = cleaner . getProperties ( ) ;
// see http://htmlcleaner.sourceforge.net/parameters.php for descriptions
properties . setNamespacesAware ( false ) ;
properties . setAdvancedXmlEscape ( false ) ;
properties . setOmitXmlDeclaration ( true ) ;
properties . setOmitDoctypeDeclaration ( false ) ;
properties . setTranslateSpecialEntities ( false ) ;
properties . setRecognizeUnicodeChars ( false ) ;
TagNode node = cleaner . clean ( content ) ;
SimpleHtmlSerializer htmlSerialized = new SimpleHtmlSerializer ( properties ) ;
try {
content = htmlSerialized . getAsString ( node , " UTF8 " ) ;
} catch ( java . io . IOException ioe ) {
// Can't imagine this happening.
Log . e ( K9 . LOG_TAG , " Problem cleaning quoted message. " , ioe ) ;
}
}
2012-05-20 16:44:32 -04:00
2011-01-12 18:48:28 -05:00
// Add the HTML reply header to the top of the content.
2011-11-14 16:16:19 -05:00
mQuotedHtmlContent = quoteOriginalHtmlMessage ( mSourceMessage , content , mQuoteStyle ) ;
2012-05-20 16:44:32 -04:00
2011-01-12 18:48:28 -05:00
// Load the message with the reply header.
2013-03-01 11:26:52 -05:00
mQuotedHTML . setText ( mQuotedHtmlContent . getQuotedContent ( ) ) ;
2012-05-20 16:44:32 -04:00
// TODO: Also strip the signature from the text/plain part
2013-10-08 19:14:08 -04:00
mQuotedText . setCharacters ( quoteOriginalTextMessage ( mSourceMessage ,
2012-05-20 16:44:32 -04:00
getBodyTextFromMessage ( mSourceMessage , SimpleMessageFormat . TEXT ) , mQuoteStyle ) ) ;
2011-01-12 18:48:28 -05:00
2012-05-20 16:44:32 -04:00
} else if ( mQuotedTextFormat = = SimpleMessageFormat . TEXT ) {
2012-05-19 21:13:58 -04:00
if ( mAccount . isStripSignature ( ) & &
( mAction = = Action . REPLY | | mAction = = Action . REPLY_ALL ) ) {
2011-11-14 16:58:01 -05:00
if ( DASH_SIGNATURE_PLAIN . matcher ( content ) . find ( ) ) {
content = DASH_SIGNATURE_PLAIN . matcher ( content ) . replaceFirst ( " \ r \ n " ) ;
}
}
2012-05-20 16:44:32 -04:00
2013-10-08 19:14:08 -04:00
mQuotedText . setCharacters ( quoteOriginalTextMessage ( mSourceMessage , content , mQuoteStyle ) ) ;
2011-05-14 11:15:01 -04:00
}
2011-01-12 18:48:28 -05:00
2012-01-22 00:25:06 -05:00
if ( showQuotedText ) {
2011-05-10 11:54:17 -04:00
showOrHideQuotedText ( QuotedTextMode . SHOW ) ;
2011-06-01 16:03:56 -04:00
} else {
2011-05-14 11:15:01 -04:00
showOrHideQuotedText ( QuotedTextMode . HIDE ) ;
}
2011-01-12 18:48:28 -05:00
}
/ * *
* Fetch the body text from a message in the desired message format . This method handles
* conversions between formats ( html to text and vice versa ) if necessary .
* @param message Message to analyze for body part .
* @param format Desired format .
* @return Text in desired format .
* @throws MessagingException
* /
2012-05-20 16:44:32 -04:00
private String getBodyTextFromMessage ( final Message message , final SimpleMessageFormat format )
throws MessagingException {
2011-01-12 18:48:28 -05:00
Part part ;
2012-05-20 16:44:32 -04:00
if ( format = = SimpleMessageFormat . HTML ) {
2011-01-12 18:48:28 -05:00
// HTML takes precedence, then text.
part = MimeUtility . findFirstPartByMimeType ( message , " text/html " ) ;
2011-02-06 17:09:48 -05:00
if ( part ! = null ) {
if ( K9 . DEBUG )
2011-01-12 18:48:28 -05:00
Log . d ( K9 . LOG_TAG , " getBodyTextFromMessage: HTML requested, HTML found. " ) ;
return MimeUtility . getTextFromPart ( part ) ;
}
part = MimeUtility . findFirstPartByMimeType ( message , " text/plain " ) ;
2011-02-06 17:09:48 -05:00
if ( part ! = null ) {
if ( K9 . DEBUG )
2011-01-12 18:48:28 -05:00
Log . d ( K9 . LOG_TAG , " getBodyTextFromMessage: HTML requested, text found. " ) ;
2013-03-01 07:13:48 -05:00
return HtmlConverter . textToHtml ( MimeUtility . getTextFromPart ( part ) ) ;
2011-01-12 18:48:28 -05:00
}
2012-05-20 16:44:32 -04:00
} else if ( format = = SimpleMessageFormat . TEXT ) {
2011-01-12 18:48:28 -05:00
// Text takes precedence, then html.
part = MimeUtility . findFirstPartByMimeType ( message , " text/plain " ) ;
2011-02-06 17:09:48 -05:00
if ( part ! = null ) {
if ( K9 . DEBUG )
2011-01-12 18:48:28 -05:00
Log . d ( K9 . LOG_TAG , " getBodyTextFromMessage: Text requested, text found. " ) ;
return MimeUtility . getTextFromPart ( part ) ;
}
part = MimeUtility . findFirstPartByMimeType ( message , " text/html " ) ;
2011-02-06 17:09:48 -05:00
if ( part ! = null ) {
if ( K9 . DEBUG )
2011-01-12 18:48:28 -05:00
Log . d ( K9 . LOG_TAG , " getBodyTextFromMessage: Text requested, HTML found. " ) ;
return HtmlConverter . htmlToText ( MimeUtility . getTextFromPart ( part ) ) ;
}
}
// If we had nothing interesting, return an empty string.
return " " ;
}
// Regular expressions to look for various HTML tags. This is no HTML::Parser, but hopefully it's good enough for
// our purposes.
private static final Pattern FIND_INSERTION_POINT_HTML = Pattern . compile ( " (?si:.*?(<html(?:>| \\ s+[^>]*>)).*) " ) ;
private static final Pattern FIND_INSERTION_POINT_HEAD = Pattern . compile ( " (?si:.*?(<head(?:>| \\ s+[^>]*>)).*) " ) ;
private static final Pattern FIND_INSERTION_POINT_BODY = Pattern . compile ( " (?si:.*?(<body(?:>| \\ s+[^>]*>)).*) " ) ;
private static final Pattern FIND_INSERTION_POINT_HTML_END = Pattern . compile ( " (?si:.*(</html>).*?) " ) ;
private static final Pattern FIND_INSERTION_POINT_BODY_END = Pattern . compile ( " (?si:.*(</body>).*?) " ) ;
// The first group in a Matcher contains the first capture group. We capture the tag found in the above REs so that
// we can locate the *end* of that tag.
private static final int FIND_INSERTION_POINT_FIRST_GROUP = 1 ;
// HTML bits to insert as appropriate
// TODO is it safe to assume utf-8 here?
2013-10-08 17:07:21 -04:00
private static final String FIND_INSERTION_POINT_HTML_CONTENT = " <!DOCTYPE html PUBLIC \" -//W3C//DTD HTML 4.0 Transitional//EN \" > \ r \ n<html> " ;
2011-01-12 18:48:28 -05:00
private static final String FIND_INSERTION_POINT_HTML_END_CONTENT = " </html> " ;
private static final String FIND_INSERTION_POINT_HEAD_CONTENT = " <head><meta content= \" text/html; charset=utf-8 \" http-equiv= \" Content-Type \" ></head> " ;
// Index of the start of the beginning of a String.
private static final int FIND_INSERTION_POINT_START_OF_STRING = 0 ;
2012-09-13 22:08:17 -04:00
2011-01-12 18:48:28 -05:00
/ * *
* < p > Find the start and end positions of the HTML in the string . This should be the very top
* and bottom of the displayable message . It returns a { @link InsertableHtmlContent } , which
* contains both the insertion points and potentially modified HTML . The modified HTML should be
* used in place of the HTML in the original message . < / p >
*
* < p > This method loosely mimics the HTML forward / reply behavior of BlackBerry OS 4 . 5 / BIS 2 . 5 , which in turn mimics
* Outlook 2003 ( as best I can tell ) . < / p >
*
* @param content Content to examine for HTML insertion points
* @return Insertion points and HTML to use for insertion .
* /
2011-02-06 17:09:48 -05:00
private InsertableHtmlContent findInsertionPoints ( final String content ) {
2011-01-12 18:48:28 -05:00
InsertableHtmlContent insertable = new InsertableHtmlContent ( ) ;
// If there is no content, don't bother doing any of the regex dancing.
2011-02-06 17:09:48 -05:00
if ( content = = null | | content . equals ( " " ) ) {
2011-01-12 18:48:28 -05:00
return insertable ;
}
// Search for opening tags.
boolean hasHtmlTag = false ;
boolean hasHeadTag = false ;
boolean hasBodyTag = false ;
// First see if we have an opening HTML tag. If we don't find one, we'll add one later.
Matcher htmlMatcher = FIND_INSERTION_POINT_HTML . matcher ( content ) ;
2011-02-06 17:09:48 -05:00
if ( htmlMatcher . matches ( ) ) {
2011-01-12 18:48:28 -05:00
hasHtmlTag = true ;
}
// Look for a HEAD tag. If we're missing a BODY tag, we'll use the close of the HEAD to start our content.
Matcher headMatcher = FIND_INSERTION_POINT_HEAD . matcher ( content ) ;
2011-02-06 17:09:48 -05:00
if ( headMatcher . matches ( ) ) {
2011-01-12 18:48:28 -05:00
hasHeadTag = true ;
}
// Look for a BODY tag. This is the ideal place for us to start our content.
Matcher bodyMatcher = FIND_INSERTION_POINT_BODY . matcher ( content ) ;
2011-02-06 17:09:48 -05:00
if ( bodyMatcher . matches ( ) ) {
2011-01-12 18:48:28 -05:00
hasBodyTag = true ;
}
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Open: hasHtmlTag: " + hasHtmlTag + " hasHeadTag: " + hasHeadTag + " hasBodyTag: " + hasBodyTag ) ;
// Given our inspections, let's figure out where to start our content.
// This is the ideal case -- there's a BODY tag and we insert ourselves just after it.
2011-02-06 17:09:48 -05:00
if ( hasBodyTag ) {
2011-01-12 18:48:28 -05:00
insertable . setQuotedContent ( new StringBuilder ( content ) ) ;
insertable . setHeaderInsertionPoint ( bodyMatcher . end ( FIND_INSERTION_POINT_FIRST_GROUP ) ) ;
2011-02-06 17:09:48 -05:00
} else if ( hasHeadTag ) {
2011-01-12 18:48:28 -05:00
// Now search for a HEAD tag. We can insert after there.
// If BlackBerry sees a HEAD tag, it inserts right after that, so long as there is no BODY tag. It doesn't
// try to add BODY, either. Right or wrong, it seems to work fine.
insertable . setQuotedContent ( new StringBuilder ( content ) ) ;
insertable . setHeaderInsertionPoint ( headMatcher . end ( FIND_INSERTION_POINT_FIRST_GROUP ) ) ;
2011-02-06 17:09:48 -05:00
} else if ( hasHtmlTag ) {
2011-01-12 18:48:28 -05:00
// Lastly, check for an HTML tag.
// In this case, it will add a HEAD, but no BODY.
StringBuilder newContent = new StringBuilder ( content ) ;
// Insert the HEAD content just after the HTML tag.
newContent . insert ( htmlMatcher . end ( FIND_INSERTION_POINT_FIRST_GROUP ) , FIND_INSERTION_POINT_HEAD_CONTENT ) ;
insertable . setQuotedContent ( newContent ) ;
// The new insertion point is the end of the HTML tag, plus the length of the HEAD content.
insertable . setHeaderInsertionPoint ( htmlMatcher . end ( FIND_INSERTION_POINT_FIRST_GROUP ) + FIND_INSERTION_POINT_HEAD_CONTENT . length ( ) ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-01-12 18:48:28 -05:00
// If we have none of the above, we probably have a fragment of HTML. Yahoo! and Gmail both do this.
// Again, we add a HEAD, but not BODY.
StringBuilder newContent = new StringBuilder ( content ) ;
// Add the HTML and HEAD tags.
newContent . insert ( FIND_INSERTION_POINT_START_OF_STRING , FIND_INSERTION_POINT_HEAD_CONTENT ) ;
newContent . insert ( FIND_INSERTION_POINT_START_OF_STRING , FIND_INSERTION_POINT_HTML_CONTENT ) ;
// Append the </HTML> tag.
newContent . append ( FIND_INSERTION_POINT_HTML_END_CONTENT ) ;
insertable . setQuotedContent ( newContent ) ;
insertable . setHeaderInsertionPoint ( FIND_INSERTION_POINT_HTML_CONTENT . length ( ) + FIND_INSERTION_POINT_HEAD_CONTENT . length ( ) ) ;
}
// Search for closing tags. We have to do this after we deal with opening tags since it may
// have modified the message.
boolean hasHtmlEndTag = false ;
boolean hasBodyEndTag = false ;
// First see if we have an opening HTML tag. If we don't find one, we'll add one later.
Matcher htmlEndMatcher = FIND_INSERTION_POINT_HTML_END . matcher ( insertable . getQuotedContent ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( htmlEndMatcher . matches ( ) ) {
2011-01-12 18:48:28 -05:00
hasHtmlEndTag = true ;
}
// Look for a BODY tag. This is the ideal place for us to place our footer.
Matcher bodyEndMatcher = FIND_INSERTION_POINT_BODY_END . matcher ( insertable . getQuotedContent ( ) ) ;
2011-02-06 17:09:48 -05:00
if ( bodyEndMatcher . matches ( ) ) {
2011-01-12 18:48:28 -05:00
hasBodyEndTag = true ;
}
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Close: hasHtmlEndTag: " + hasHtmlEndTag + " hasBodyEndTag: " + hasBodyEndTag ) ;
// Now figure out where to put our footer.
// This is the ideal case -- there's a BODY tag and we insert ourselves just before it.
2011-02-06 17:09:48 -05:00
if ( hasBodyEndTag ) {
2011-01-12 18:48:28 -05:00
insertable . setFooterInsertionPoint ( bodyEndMatcher . start ( FIND_INSERTION_POINT_FIRST_GROUP ) ) ;
2011-02-06 17:09:48 -05:00
} else if ( hasHtmlEndTag ) {
2011-01-12 18:48:28 -05:00
// Check for an HTML tag. Add ourselves just before it.
insertable . setFooterInsertionPoint ( htmlEndMatcher . start ( FIND_INSERTION_POINT_FIRST_GROUP ) ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-01-12 18:48:28 -05:00
// If we have none of the above, we probably have a fragment of HTML.
// Set our footer insertion point as the end of the string.
insertable . setFooterInsertionPoint ( insertable . getQuotedContent ( ) . length ( ) ) ;
}
return insertable ;
}
2011-02-06 17:09:48 -05:00
class Listener extends MessagingListener {
2008-11-01 17:32:06 -04:00
@Override
2011-02-06 17:09:48 -05:00
public void loadMessageForViewStarted ( Account account , String folder , String uid ) {
if ( ( mMessageReference = = null ) | | ! mMessageReference . uid . equals ( uid ) ) {
2009-10-17 23:30:42 -04:00
return ;
}
2008-11-01 17:32:06 -04:00
mHandler . sendEmptyMessage ( MSG_PROGRESS_ON ) ;
}
@Override
2011-02-06 17:09:48 -05:00
public void loadMessageForViewFinished ( Account account , String folder , String uid , Message message ) {
if ( ( mMessageReference = = null ) | | ! mMessageReference . uid . equals ( uid ) ) {
2009-10-17 23:30:42 -04:00
return ;
}
2008-11-01 17:32:06 -04:00
mHandler . sendEmptyMessage ( MSG_PROGRESS_OFF ) ;
}
@Override
2011-02-06 17:09:48 -05:00
public void loadMessageForViewBodyAvailable ( Account account , String folder , String uid , final Message message ) {
if ( ( mMessageReference = = null ) | | ! mMessageReference . uid . equals ( uid ) ) {
2009-10-17 23:30:42 -04:00
return ;
}
2008-11-01 17:32:06 -04:00
mSourceMessage = message ;
2011-02-06 17:09:48 -05:00
runOnUiThread ( new Runnable ( ) {
2012-01-22 00:25:06 -05:00
@Override
2011-02-06 17:09:48 -05:00
public void run ( ) {
2011-02-05 18:14:02 -05:00
// We check to see if we've previously processed the source message since this
// could be called when switching from HTML to text replies. If that happens, we
// only want to update the UI with quoted text (which picks the appropriate
// part).
2011-02-06 17:09:48 -05:00
if ( mSourceProcessed ) {
try {
2011-05-14 11:15:01 -04:00
populateUIWithQuotedMessage ( true ) ;
2011-02-06 17:09:48 -05:00
} catch ( MessagingException e ) {
2011-02-05 18:14:02 -05:00
// Hm, if we couldn't populate the UI after source reprocessing, let's just delete it?
2011-05-10 11:54:17 -04:00
showOrHideQuotedText ( QuotedTextMode . HIDE ) ;
2011-02-05 18:14:02 -05:00
Log . e ( K9 . LOG_TAG , " Could not re-process source message; deleting quoted text to be safe. " , e ) ;
}
2012-05-20 16:44:32 -04:00
updateMessageFormat ( ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-02-05 18:14:02 -05:00
processSourceMessage ( message ) ;
mSourceProcessed = true ;
}
2008-11-01 17:32:06 -04:00
}
} ) ;
}
@Override
2011-02-06 17:09:48 -05:00
public void loadMessageForViewFailed ( Account account , String folder , String uid , Throwable t ) {
if ( ( mMessageReference = = null ) | | ! mMessageReference . uid . equals ( uid ) ) {
2009-10-17 23:30:42 -04:00
return ;
}
2008-11-01 17:32:06 -04:00
mHandler . sendEmptyMessage ( MSG_PROGRESS_OFF ) ;
// TODO show network error
}
@Override
2011-02-06 17:09:48 -05:00
public void messageUidChanged ( Account account , String folder , String oldUid , String newUid ) {
2010-07-21 23:15:28 -04:00
// Track UID changes of the source message
2011-02-06 17:09:48 -05:00
if ( mMessageReference ! = null ) {
2010-07-21 23:15:28 -04:00
final Account sourceAccount = Preferences . getPreferences ( MessageCompose . this ) . getAccount ( mMessageReference . accountUuid ) ;
final String sourceFolder = mMessageReference . folderName ;
2010-07-21 23:40:30 -04:00
final String sourceMessageUid = mMessageReference . uid ;
2011-02-06 17:09:48 -05:00
if ( account . equals ( sourceAccount ) & & ( folder . equals ( sourceFolder ) ) ) {
if ( oldUid . equals ( sourceMessageUid ) ) {
2010-07-21 23:15:28 -04:00
mMessageReference . uid = newUid ;
}
2011-02-06 17:09:48 -05:00
if ( ( mSourceMessage ! = null ) & & ( oldUid . equals ( mSourceMessage . getUid ( ) ) ) ) {
2010-07-21 23:15:28 -04:00
mSourceMessage . setUid ( newUid ) ;
}
2008-11-01 17:32:06 -04:00
}
}
}
}
2010-01-28 01:25:10 -05:00
/ * *
* When we are launched with an intent that includes a mailto : URI , we can actually
* gather quite a few of our message fields from it .
2012-01-22 00:25:06 -05:00
*
* @param mailtoUri
* The mailto : URI we use to initialize the message fields .
2010-01-28 01:25:10 -05:00
* /
2011-02-06 17:09:48 -05:00
private void initializeFromMailto ( Uri mailtoUri ) {
2010-11-13 21:27:42 -05:00
String schemaSpecific = mailtoUri . getSchemeSpecificPart ( ) ;
int end = schemaSpecific . indexOf ( '?' ) ;
2011-02-06 17:09:48 -05:00
if ( end = = - 1 ) {
2010-11-13 21:27:42 -05:00
end = schemaSpecific . length ( ) ;
2010-04-29 00:59:14 -04:00
}
2010-01-28 01:25:10 -05:00
2010-11-13 21:27:42 -05:00
// Extract the recipient's email address from the mailto URI if there's one.
String recipient = Uri . decode ( schemaSpecific . substring ( 0 , end ) ) ;
2010-01-28 01:25:10 -05:00
2010-11-13 21:27:42 -05:00
/ *
* mailto URIs are not hierarchical . So calling getQueryParameters ( )
* will throw an UnsupportedOperationException . We avoid this by
* creating a new hierarchical dummy Uri object with the query
* parameters of the original URI .
* /
2012-11-12 17:41:06 -05:00
CaseInsensitiveParamWrapper uri = new CaseInsensitiveParamWrapper (
Uri . parse ( " foo://bar? " + mailtoUri . getEncodedQuery ( ) ) ) ;
2010-01-28 01:25:10 -05:00
2010-11-13 21:27:42 -05:00
// Read additional recipients from the "to" parameter.
List < String > to = uri . getQueryParameters ( " to " ) ;
2011-02-06 17:09:48 -05:00
if ( recipient . length ( ) ! = 0 ) {
2010-11-13 21:27:42 -05:00
to = new ArrayList < String > ( to ) ;
to . add ( 0 , recipient ) ;
2010-01-28 01:25:10 -05:00
}
2012-05-06 11:47:59 -04:00
addRecipients ( mToView , to ) ;
2010-11-13 21:27:42 -05:00
// Read carbon copy recipients from the "cc" parameter.
2012-05-06 11:47:59 -04:00
boolean ccOrBcc = addRecipients ( mCcView , uri . getQueryParameters ( " cc " ) ) ;
2010-11-13 21:27:42 -05:00
// Read blind carbon copy recipients from the "bcc" parameter.
2012-05-06 11:47:59 -04:00
ccOrBcc | = addRecipients ( mBccView , uri . getQueryParameters ( " bcc " ) ) ;
2010-01-28 01:25:10 -05:00
2011-02-06 17:09:48 -05:00
if ( ccOrBcc ) {
2010-11-13 21:27:42 -05:00
// Display CC and BCC text fields if CC or BCC recipients were set by the intent.
onAddCcBcc ( ) ;
2010-01-28 01:25:10 -05:00
}
2010-11-13 21:27:42 -05:00
// Read subject from the "subject" parameter.
2010-01-28 01:25:10 -05:00
List < String > subject = uri . getQueryParameters ( " subject " ) ;
2011-10-06 12:28:14 -04:00
if ( ! subject . isEmpty ( ) ) {
2010-01-28 01:25:10 -05:00
mSubjectView . setText ( subject . get ( 0 ) ) ;
}
2010-11-13 21:27:42 -05:00
// Read message body from the "body" parameter.
2010-01-28 01:25:10 -05:00
List < String > body = uri . getQueryParameters ( " body " ) ;
2011-10-06 12:28:14 -04:00
if ( ! body . isEmpty ( ) ) {
2013-10-08 19:14:08 -04:00
mMessageContentView . setCharacters ( body . get ( 0 ) ) ;
2010-01-28 01:25:10 -05:00
}
2010-04-29 00:59:14 -04:00
}
2010-07-21 23:40:22 -04:00
2012-11-12 17:41:06 -05:00
private static class CaseInsensitiveParamWrapper {
private final Uri uri ;
2012-11-16 12:28:40 -05:00
private Set < String > mParamNames ;
2012-11-12 17:41:06 -05:00
public CaseInsensitiveParamWrapper ( Uri uri ) {
this . uri = uri ;
}
public List < String > getQueryParameters ( String key ) {
final List < String > params = new ArrayList < String > ( ) ;
2012-11-16 12:28:40 -05:00
for ( String paramName : getQueryParameterNames ( ) ) {
2012-11-12 17:41:06 -05:00
if ( paramName . equalsIgnoreCase ( key ) ) {
params . addAll ( uri . getQueryParameters ( paramName ) ) ;
}
}
return params ;
}
2012-11-16 12:28:40 -05:00
@TargetApi ( 11 )
private Set < String > getQueryParameterNames ( ) {
if ( Build . VERSION . SDK_INT > = 11 ) {
return uri . getQueryParameterNames ( ) ;
}
return getQueryParameterNamesPreSdk11 ( ) ;
}
private Set < String > getQueryParameterNamesPreSdk11 ( ) {
if ( mParamNames = = null ) {
String query = uri . getQuery ( ) ;
Set < String > paramNames = new HashSet < String > ( ) ;
Collections . addAll ( paramNames , query . split ( " (=[^&]*(&|$))|& " ) ) ;
mParamNames = paramNames ;
}
return mParamNames ;
}
2012-11-12 17:41:06 -05:00
}
2011-02-06 17:09:48 -05:00
private class SendMessageTask extends AsyncTask < Void , Void , Void > {
2010-07-28 19:17:46 -04:00
@Override
2011-02-06 17:09:48 -05:00
protected Void doInBackground ( Void . . . params ) {
2010-07-21 23:40:22 -04:00
/ *
* Create the message from all the data the user has entered .
* /
MimeMessage message ;
2011-02-06 17:09:48 -05:00
try {
2011-01-12 18:48:28 -05:00
message = createMessage ( false ) ; // isDraft = true
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2010-07-21 23:40:22 -04:00
Log . e ( K9 . LOG_TAG , " Failed to create new message for send or save. " , me ) ;
throw new RuntimeException ( " Failed to create a new message for send or save. " , me ) ;
}
2011-02-06 17:09:48 -05:00
try {
2011-03-22 03:06:11 -04:00
mContacts . markAsContacted ( message . getRecipients ( RecipientType . TO ) ) ;
mContacts . markAsContacted ( message . getRecipients ( RecipientType . CC ) ) ;
mContacts . markAsContacted ( message . getRecipients ( RecipientType . BCC ) ) ;
2011-02-06 17:09:48 -05:00
} catch ( Exception e ) {
2010-10-30 16:35:49 -04:00
Log . e ( K9 . LOG_TAG , " Failed to mark contact as contacted. " , e ) ;
}
2010-07-21 23:40:22 -04:00
MessagingController . getInstance ( getApplication ( ) ) . sendMessage ( mAccount , message , null ) ;
2012-01-25 18:37:25 -05:00
long draftId = mDraftId ;
if ( draftId ! = INVALID_DRAFT_ID ) {
2012-01-21 23:14:58 -05:00
mDraftId = INVALID_DRAFT_ID ;
2012-01-25 18:37:25 -05:00
MessagingController . getInstance ( getApplication ( ) ) . deleteDraft ( mAccount , draftId ) ;
2010-07-21 23:40:22 -04:00
}
return null ;
}
}
2011-02-06 17:09:48 -05:00
private class SaveMessageTask extends AsyncTask < Void , Void , Void > {
2010-07-28 19:17:46 -04:00
@Override
2011-02-06 17:09:48 -05:00
protected Void doInBackground ( Void . . . params ) {
2010-07-21 23:40:22 -04:00
/ *
* Create the message from all the data the user has entered .
* /
MimeMessage message ;
2011-02-06 17:09:48 -05:00
try {
2011-01-12 18:48:28 -05:00
message = createMessage ( true ) ; // isDraft = true
2011-02-06 17:09:48 -05:00
} catch ( MessagingException me ) {
2010-07-21 23:40:22 -04:00
Log . e ( K9 . LOG_TAG , " Failed to create new message for send or save. " , me ) ;
throw new RuntimeException ( " Failed to create a new message for send or save. " , me ) ;
}
/ *
* Save a draft
* /
2012-05-19 21:13:58 -04:00
if ( mAction = = Action . EDIT_DRAFT ) {
2010-07-21 23:40:22 -04:00
/ *
* We ' re saving a previously saved draft , so update the new message ' s uid
* to the old message ' s uid .
* /
2011-02-06 17:09:48 -05:00
if ( mMessageReference ! = null ) {
2010-10-23 11:26:50 -04:00
message . setUid ( mMessageReference . uid ) ;
}
2010-07-21 23:40:22 -04:00
}
2010-11-13 16:40:56 -05:00
final MessagingController messagingController = MessagingController . getInstance ( getApplication ( ) ) ;
2012-01-21 23:14:58 -05:00
Message draftMessage = messagingController . saveDraft ( mAccount , message , mDraftId ) ;
mDraftId = messagingController . getId ( draftMessage ) ;
2010-07-21 23:40:22 -04:00
2011-11-01 04:02:29 -04:00
mHandler . sendEmptyMessage ( MSG_SAVED_DRAFT ) ;
2010-07-21 23:40:22 -04:00
return null ;
}
}
2011-01-05 18:58:14 -05:00
private static final int REPLY_WRAP_LINE_WIDTH = 72 ;
private static final int QUOTE_BUFFER_LENGTH = 512 ; // amount of extra buffer to allocate to accommodate quoting headers or prefixes
/ * *
2011-01-12 18:48:28 -05:00
* Add quoting markup to a text message .
2011-01-05 18:58:14 -05:00
* @param originalMessage Metadata for message being quoted .
2011-01-05 20:31:28 -05:00
* @param messageBody Text of the message to be quoted .
2011-01-05 18:58:14 -05:00
* @param quoteStyle Style of quoting .
* @return Quoted text .
* @throws MessagingException
* /
2011-02-06 17:09:48 -05:00
private String quoteOriginalTextMessage ( final Message originalMessage , final String messageBody , final QuoteStyle quoteStyle ) throws MessagingException {
2011-01-05 20:31:28 -05:00
String body = messageBody = = null ? " " : messageBody ;
2013-10-10 16:51:39 -04:00
String sentDate = getSentDateText ( originalMessage ) ;
2011-02-06 17:09:48 -05:00
if ( quoteStyle = = QuoteStyle . PREFIX ) {
2011-01-05 18:58:14 -05:00
StringBuilder quotedText = new StringBuilder ( body . length ( ) + QUOTE_BUFFER_LENGTH ) ;
2013-10-10 16:51:39 -04:00
if ( sentDate . length ( ) ! = 0 ) {
quotedText . append ( String . format (
getString ( R . string . message_compose_reply_header_fmt_with_date ) + " \ r \ n " ,
sentDate ,
Address . toString ( originalMessage . getFrom ( ) ) ) ) ;
} else {
quotedText . append ( String . format (
getString ( R . string . message_compose_reply_header_fmt ) + " \ r \ n " ,
Address . toString ( originalMessage . getFrom ( ) ) )
) ;
}
2011-01-05 18:58:14 -05:00
final String prefix = mAccount . getQuotePrefix ( ) ;
final String wrappedText = Utility . wrap ( body , REPLY_WRAP_LINE_WIDTH - prefix . length ( ) ) ;
// "$" and "\" in the quote prefix have to be escaped for
// the replaceAll() invocation.
final String escapedPrefix = prefix . replaceAll ( " ( \\ \\ | \\ $) " , " \\ \\ $1 " ) ;
quotedText . append ( wrappedText . replaceAll ( " (?m)^ " , escapedPrefix ) ) ;
return quotedText . toString ( ) . replaceAll ( " \\ \ r " , " " ) ;
2011-02-06 17:09:48 -05:00
} else if ( quoteStyle = = QuoteStyle . HEADER ) {
2011-01-05 18:58:14 -05:00
StringBuilder quotedText = new StringBuilder ( body . length ( ) + QUOTE_BUFFER_LENGTH ) ;
2013-10-08 17:07:21 -04:00
quotedText . append ( " \ r \ n " ) ;
quotedText . append ( getString ( R . string . message_compose_quote_header_separator ) ) . append ( " \ r \ n " ) ;
2011-02-06 17:09:48 -05:00
if ( originalMessage . getFrom ( ) ! = null & & Address . toString ( originalMessage . getFrom ( ) ) . length ( ) ! = 0 ) {
2013-10-08 17:07:21 -04:00
quotedText . append ( getString ( R . string . message_compose_quote_header_from ) ) . append ( " " ) . append ( Address . toString ( originalMessage . getFrom ( ) ) ) . append ( " \ r \ n " ) ;
2011-01-05 18:58:14 -05:00
}
2013-10-10 16:51:39 -04:00
if ( sentDate . length ( ) ! = 0 ) {
quotedText . append ( getString ( R . string . message_compose_quote_header_send_date ) ) . append ( " " ) . append ( sentDate ) . append ( " \ r \ n " ) ;
2011-01-05 18:58:14 -05:00
}
2011-02-06 17:09:48 -05:00
if ( originalMessage . getRecipients ( RecipientType . TO ) ! = null & & originalMessage . getRecipients ( RecipientType . TO ) . length ! = 0 ) {
2013-10-08 17:07:21 -04:00
quotedText . append ( getString ( R . string . message_compose_quote_header_to ) ) . append ( " " ) . append ( Address . toString ( originalMessage . getRecipients ( RecipientType . TO ) ) ) . append ( " \ r \ n " ) ;
2011-01-05 18:58:14 -05:00
}
2011-02-06 17:09:48 -05:00
if ( originalMessage . getRecipients ( RecipientType . CC ) ! = null & & originalMessage . getRecipients ( RecipientType . CC ) . length ! = 0 ) {
2013-10-08 17:07:21 -04:00
quotedText . append ( getString ( R . string . message_compose_quote_header_cc ) ) . append ( " " ) . append ( Address . toString ( originalMessage . getRecipients ( RecipientType . CC ) ) ) . append ( " \ r \ n " ) ;
2011-01-05 18:58:14 -05:00
}
2011-02-06 17:09:48 -05:00
if ( originalMessage . getSubject ( ) ! = null ) {
2013-10-08 17:07:21 -04:00
quotedText . append ( getString ( R . string . message_compose_quote_header_subject ) ) . append ( " " ) . append ( originalMessage . getSubject ( ) ) . append ( " \ r \ n " ) ;
2011-01-05 18:58:14 -05:00
}
2013-10-08 17:07:21 -04:00
quotedText . append ( " \ r \ n " ) ;
2011-01-05 18:58:14 -05:00
2011-01-05 20:31:28 -05:00
quotedText . append ( body ) ;
2011-01-05 18:58:14 -05:00
return quotedText . toString ( ) ;
2011-02-06 17:09:48 -05:00
} else {
2011-01-05 18:58:14 -05:00
// Shouldn't ever happen.
return body ;
}
}
2011-01-12 18:48:28 -05:00
/ * *
* Add quoting markup to a HTML message .
* @param originalMessage Metadata for message being quoted .
* @param messageBody Text of the message to be quoted .
* @param quoteStyle Style of quoting .
* @return Modified insertable message .
* @throws MessagingException
* /
2011-02-06 17:09:48 -05:00
private InsertableHtmlContent quoteOriginalHtmlMessage ( final Message originalMessage , final String messageBody , final QuoteStyle quoteStyle ) throws MessagingException {
2011-01-12 18:48:28 -05:00
InsertableHtmlContent insertable = findInsertionPoints ( messageBody ) ;
2013-10-10 16:51:39 -04:00
String sentDate = getSentDateText ( originalMessage ) ;
2011-02-06 17:09:48 -05:00
if ( quoteStyle = = QuoteStyle . PREFIX ) {
2011-01-12 18:48:28 -05:00
StringBuilder header = new StringBuilder ( QUOTE_BUFFER_LENGTH ) ;
2011-01-28 16:41:06 -05:00
header . append ( " <div class= \" gmail_quote \" > " ) ;
2013-10-10 16:51:39 -04:00
if ( sentDate . length ( ) ! = 0 ) {
header . append ( HtmlConverter . textToHtmlFragment ( String . format (
getString ( R . string . message_compose_reply_header_fmt_with_date ) ,
sentDate ,
Address . toString ( originalMessage . getFrom ( ) ) )
) ) ;
} else {
header . append ( HtmlConverter . textToHtmlFragment ( String . format (
getString ( R . string . message_compose_reply_header_fmt ) ,
Address . toString ( originalMessage . getFrom ( ) ) )
) ) ;
}
2011-01-12 18:48:28 -05:00
header . append ( " <blockquote class= \" gmail_quote \" " +
2013-10-08 17:07:21 -04:00
" style= \" margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex; \" > \ r \ n " ) ;
2011-01-12 18:48:28 -05:00
String footer = " </blockquote></div> " ;
insertable . insertIntoQuotedHeader ( header . toString ( ) ) ;
insertable . insertIntoQuotedFooter ( footer ) ;
2011-02-06 17:09:48 -05:00
} else if ( quoteStyle = = QuoteStyle . HEADER ) {
2011-01-12 18:48:28 -05:00
StringBuilder header = new StringBuilder ( ) ;
2013-10-08 17:07:21 -04:00
header . append ( " <div style='font-size:10.0pt;font-family: \" Tahoma \" , \" sans-serif \" ;padding:3.0pt 0in 0in 0in'> \ r \ n " ) ;
header . append ( " <hr style='border:none;border-top:solid #E1E1E1 1.0pt'> \ r \ n " ) ; // This gets converted into a horizontal line during html to text conversion.
2013-10-10 16:51:39 -04:00
if ( originalMessage . getFrom ( ) ! = null & & Address . toString ( originalMessage . getFrom ( ) ) . length ( ) ! = 0 ) {
2012-12-21 18:36:54 -05:00
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_from ) ) . append ( " </b> " )
2013-10-10 16:51:39 -04:00
. append ( HtmlConverter . textToHtmlFragment ( Address . toString ( originalMessage . getFrom ( ) ) ) )
2013-10-08 17:07:21 -04:00
. append ( " <br> \ r \ n " ) ;
2011-01-12 18:48:28 -05:00
}
2013-10-10 16:51:39 -04:00
if ( sentDate . length ( ) ! = 0 ) {
2012-12-21 18:36:54 -05:00
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_send_date ) ) . append ( " </b> " )
2013-10-10 16:51:39 -04:00
. append ( sentDate )
2013-10-08 17:07:21 -04:00
. append ( " <br> \ r \ n " ) ;
2011-01-12 18:48:28 -05:00
}
2013-10-10 16:51:39 -04:00
if ( originalMessage . getRecipients ( RecipientType . TO ) ! = null & & originalMessage . getRecipients ( RecipientType . TO ) . length ! = 0 ) {
2012-12-21 18:36:54 -05:00
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_to ) ) . append ( " </b> " )
2013-10-10 16:51:39 -04:00
. append ( HtmlConverter . textToHtmlFragment ( Address . toString ( originalMessage . getRecipients ( RecipientType . TO ) ) ) )
2013-10-08 17:07:21 -04:00
. append ( " <br> \ r \ n " ) ;
2011-01-12 18:48:28 -05:00
}
2013-10-10 16:51:39 -04:00
if ( originalMessage . getRecipients ( RecipientType . CC ) ! = null & & originalMessage . getRecipients ( RecipientType . CC ) . length ! = 0 ) {
2012-12-21 18:36:54 -05:00
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_cc ) ) . append ( " </b> " )
2013-10-10 16:51:39 -04:00
. append ( HtmlConverter . textToHtmlFragment ( Address . toString ( originalMessage . getRecipients ( RecipientType . CC ) ) ) )
2013-10-08 17:07:21 -04:00
. append ( " <br> \ r \ n " ) ;
2011-01-12 18:48:28 -05:00
}
2013-10-10 16:51:39 -04:00
if ( originalMessage . getSubject ( ) ! = null ) {
2012-12-21 18:36:54 -05:00
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_subject ) ) . append ( " </b> " )
2013-10-10 16:51:39 -04:00
. append ( HtmlConverter . textToHtmlFragment ( originalMessage . getSubject ( ) ) )
2013-10-08 17:07:21 -04:00
. append ( " <br> \ r \ n " ) ;
2011-01-12 18:48:28 -05:00
}
2013-10-08 17:07:21 -04:00
header . append ( " </div> \ r \ n " ) ;
header . append ( " <br> \ r \ n " ) ;
2011-01-12 18:48:28 -05:00
insertable . insertIntoQuotedHeader ( header . toString ( ) ) ;
}
return insertable ;
}
2012-03-22 17:17:10 -04:00
/ * *
* Used to store an { @link Identity } instance together with the { @link Account } it belongs to .
*
* @see IdentityAdapter
* /
static class IdentityContainer {
public final Identity identity ;
public final Account account ;
IdentityContainer ( Identity identity , Account account ) {
this . identity = identity ;
this . account = account ;
}
}
/ * *
* Adapter for the < em > Choose identity < / em > list view .
*
* < p >
* Account names are displayed as section headers , identities as selectable list items .
* < / p >
* /
static class IdentityAdapter extends BaseAdapter {
private LayoutInflater mLayoutInflater ;
private List < Object > mItems ;
2012-09-15 21:16:29 -04:00
public IdentityAdapter ( Context context ) {
mLayoutInflater = ( LayoutInflater ) context . getSystemService (
Context . LAYOUT_INFLATER_SERVICE ) ;
2012-03-22 17:17:10 -04:00
List < Object > items = new ArrayList < Object > ( ) ;
Preferences prefs = Preferences . getPreferences ( context . getApplicationContext ( ) ) ;
Account [ ] accounts = prefs . getAvailableAccounts ( ) . toArray ( EMPTY_ACCOUNT_ARRAY ) ;
for ( Account account : accounts ) {
items . add ( account ) ;
List < Identity > identities = account . getIdentities ( ) ;
for ( Identity identity : identities ) {
items . add ( new IdentityContainer ( identity , account ) ) ;
}
}
mItems = items ;
}
@Override
public int getCount ( ) {
return mItems . size ( ) ;
}
@Override
public int getViewTypeCount ( ) {
return 2 ;
}
@Override
public int getItemViewType ( int position ) {
return ( mItems . get ( position ) instanceof Account ) ? 0 : 1 ;
}
@Override
public boolean isEnabled ( int position ) {
return ( mItems . get ( position ) instanceof IdentityContainer ) ;
}
@Override
public Object getItem ( int position ) {
return mItems . get ( position ) ;
}
@Override
public long getItemId ( int position ) {
return position ;
}
@Override
public boolean hasStableIds ( ) {
return false ;
}
@Override
public View getView ( int position , View convertView , ViewGroup parent ) {
Object item = mItems . get ( position ) ;
View view = null ;
if ( item instanceof Account ) {
2012-03-24 15:43:17 -04:00
if ( convertView ! = null & & convertView . getTag ( ) instanceof AccountHolder ) {
2012-03-22 17:17:10 -04:00
view = convertView ;
} else {
view = mLayoutInflater . inflate ( R . layout . choose_account_item , parent , false ) ;
2012-03-24 15:43:17 -04:00
AccountHolder holder = new AccountHolder ( ) ;
holder . name = ( TextView ) view . findViewById ( R . id . name ) ;
holder . chip = view . findViewById ( R . id . chip ) ;
view . setTag ( holder ) ;
2012-03-22 17:17:10 -04:00
}
Account account = ( Account ) item ;
2012-03-24 15:43:17 -04:00
AccountHolder holder = ( AccountHolder ) view . getTag ( ) ;
holder . name . setText ( account . getDescription ( ) ) ;
holder . chip . setBackgroundColor ( account . getChipColor ( ) ) ;
2012-03-22 17:17:10 -04:00
} else if ( item instanceof IdentityContainer ) {
if ( convertView ! = null & & convertView . getTag ( ) instanceof IdentityHolder ) {
view = convertView ;
} else {
view = mLayoutInflater . inflate ( R . layout . choose_identity_item , parent , false ) ;
IdentityHolder holder = new IdentityHolder ( ) ;
holder . name = ( TextView ) view . findViewById ( R . id . name ) ;
holder . description = ( TextView ) view . findViewById ( R . id . description ) ;
view . setTag ( holder ) ;
}
IdentityContainer identityContainer = ( IdentityContainer ) item ;
Identity identity = identityContainer . identity ;
IdentityHolder holder = ( IdentityHolder ) view . getTag ( ) ;
holder . name . setText ( identity . getDescription ( ) ) ;
holder . description . setText ( getIdentityDescription ( identity ) ) ;
}
return view ;
}
2012-03-24 15:43:17 -04:00
static class AccountHolder {
public TextView name ;
public View chip ;
}
2012-03-22 17:17:10 -04:00
static class IdentityHolder {
public TextView name ;
public TextView description ;
}
}
private static String getIdentityDescription ( Identity identity ) {
return String . format ( " %s <%s> " , identity . getName ( ) , identity . getEmail ( ) ) ;
}
2012-05-20 16:44:32 -04:00
private void setMessageFormat ( SimpleMessageFormat format ) {
// This method will later be used to enable/disable the rich text editing mode.
2012-08-09 20:31:55 -04:00
2012-05-20 16:44:32 -04:00
mMessageFormat = format ;
}
private void updateMessageFormat ( ) {
MessageFormat origMessageFormat = mAccount . getMessageFormat ( ) ;
SimpleMessageFormat messageFormat ;
if ( origMessageFormat = = MessageFormat . TEXT ) {
// The user wants to send text/plain messages. We don't override that choice under
// any circumstances.
messageFormat = SimpleMessageFormat . TEXT ;
} else if ( mForcePlainText & & includeQuotedText ( ) ) {
// Right now we send a text/plain-only message when the quoted text was edited, no
// matter what the user selected for the message format.
messageFormat = SimpleMessageFormat . TEXT ;
} else if ( mEncryptCheckbox . isChecked ( ) | | mCryptoSignatureCheckbox . isChecked ( ) ) {
// Right now we only support PGP inline which doesn't play well with HTML. So force
// plain text in those cases.
messageFormat = SimpleMessageFormat . TEXT ;
} else if ( origMessageFormat = = MessageFormat . AUTO ) {
if ( mAction = = Action . COMPOSE | | mQuotedTextFormat = = SimpleMessageFormat . TEXT | |
! includeQuotedText ( ) ) {
// If the message format is set to "AUTO" we use text/plain whenever possible. That
// is, when composing new messages and replying to or forwarding text/plain
// messages.
messageFormat = SimpleMessageFormat . TEXT ;
} else {
messageFormat = SimpleMessageFormat . HTML ;
}
} else {
// In all other cases use HTML
messageFormat = SimpleMessageFormat . HTML ;
}
setMessageFormat ( messageFormat ) ;
}
private boolean includeQuotedText ( ) {
return ( mQuotedTextMode = = QuotedTextMode . SHOW ) ;
}
2013-10-08 19:14:08 -04:00
2013-10-10 16:51:39 -04:00
/ * *
* Extract the date from a message and convert it into a locale - specific
* date string suitable for use in a header for a quoted message .
*
* @param message
* @return A string with the formatted date / time
* /
private String getSentDateText ( Message message ) {
try {
final int dateStyle = DateFormat . LONG ;
final int timeStyle = DateFormat . LONG ;
Date date = message . getSentDate ( ) ;
Locale locale = getResources ( ) . getConfiguration ( ) . locale ;
return DateFormat . getDateTimeInstance ( dateStyle , timeStyle , locale )
. format ( date ) ;
} catch ( Exception e ) {
return " " ;
}
}
2013-10-08 19:14:08 -04:00
/ * *
* An { @link EditText } extension with methods that convert line endings from
* { @code \ r \ n } to { @code \ n } and back again when setting and getting text .
*
* /
private static class EolConvertingEditText extends EditText {
public EolConvertingEditText ( Context context , AttributeSet attrs ) {
super ( context , attrs ) ;
}
/ * *
* Return the text the EolConvertingEditText is displaying .
*
* @return A string with any line endings converted to { @code \ r \ n } .
* /
public String getCharacters ( ) {
return getText ( ) . toString ( ) . replace ( " \ n " , " \ r \ n " ) ;
}
/ * *
* Sets the string value of the EolConvertingEditText . Any line endings
* in the string will be converted to { @code \ n } .
*
* @param text
* /
public void setCharacters ( CharSequence text ) {
setText ( text . toString ( ) . replace ( " \ r \ n " , " \ n " ) ) ;
}
}
2008-11-01 17:32:06 -04:00
}