2008-11-01 17:32:06 -04:00
2009-12-14 21:50:53 -05:00
package com.fsck.k9.activity ;
2008-11-01 17:32:06 -04:00
2010-07-27 08:10:09 -04:00
import java.io.File ;
import java.io.Serializable ;
2011-01-12 18:48:28 -05:00
import java.util.* ;
import java.util.regex.Matcher ;
2010-08-07 15:25:47 -04:00
import java.util.regex.Pattern ;
2010-07-27 08:10:09 -04:00
2011-01-12 18:48:28 -05:00
import android.text.* ;
import android.webkit.WebViewClient ;
import com.fsck.k9.helper.HtmlConverter ;
import com.fsck.k9.mail.* ;
import com.fsck.k9.view.MessageWebView ;
2010-07-27 08:10:09 -04:00
import org.apache.james.mime4j.codec.EncoderUtil ;
2010-07-04 13:46:55 -04:00
import android.app.AlertDialog ;
import android.app.Dialog ;
2008-11-01 17:32:06 -04:00
import android.content.ContentResolver ;
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.database.Cursor ;
import android.net.Uri ;
2010-07-21 23:40:22 -04:00
import android.os.AsyncTask ;
2008-11-01 17:32:06 -04:00
import android.os.Bundle ;
import android.os.Handler ;
import android.os.Parcelable ;
import android.provider.OpenableColumns ;
import android.text.util.Rfc822Tokenizer ;
import android.util.Log ;
2010-07-04 13:46:55 -04:00
import android.view.KeyEvent ;
2008-11-01 17:32:06 -04:00
import android.view.Menu ;
import android.view.MenuItem ;
import android.view.View ;
import android.view.View.OnClickListener ;
import android.view.View.OnFocusChangeListener ;
2009-12-09 22:16:42 -05:00
import android.view.Window ;
2011-01-12 18:48:28 -05:00
import android.webkit.WebView ;
2008-11-01 17:32:06 -04:00
import android.widget.AutoCompleteTextView.Validator ;
2010-07-27 08:10:09 -04:00
import android.widget.CheckBox ;
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.QuoteStyle ;
import com.fsck.k9.Account.MessageFormat ;
2010-07-27 08:10:09 -04:00
import com.fsck.k9.EmailAddressAdapter ;
import com.fsck.k9.EmailAddressValidator ;
import com.fsck.k9.Identity ;
import com.fsck.k9.K9 ;
import com.fsck.k9.Preferences ;
import com.fsck.k9.R ;
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 ;
2010-10-30 16:35:49 -04:00
import com.fsck.k9.helper.Contacts ;
2010-05-19 14:17:06 -04:00
import com.fsck.k9.helper.Utility ;
2009-12-14 21:50:53 -05:00
import com.fsck.k9.mail.Message.RecipientType ;
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 ;
import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBody ;
2009-12-09 22:16:42 -05:00
2009-11-24 19:40:29 -05:00
public class MessageCompose extends K9Activity implements OnClickListener , OnFocusChangeListener
{
2010-07-04 13:46:55 -04:00
private static final int DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE = 1 ;
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 " ;
2008-11-01 17:32:06 -04:00
private static final String STATE_KEY_QUOTED_TEXT_SHOWN =
2009-12-14 21:50:53 -05:00
" 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 " ;
2008-11-01 17:32:06 -04:00
private static final String STATE_KEY_DRAFT_UID =
2009-12-14 21:50:53 -05:00
" com.fsck.k9.activity.MessageCompose.draftUid " ;
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 " ;
2008-11-01 17:32:06 -04:00
private static final int MSG_PROGRESS_ON = 1 ;
private static final int MSG_PROGRESS_OFF = 2 ;
private static final int MSG_UPDATE_TITLE = 3 ;
private static final int MSG_SKIPPED_ATTACHMENTS = 4 ;
private static final int MSG_SAVED_DRAFT = 5 ;
private static final int MSG_DISCARDED_DRAFT = 6 ;
private static final int ACTIVITY_REQUEST_PICK_ATTACHMENT = 1 ;
2009-06-08 23:11:35 -04:00
private static final int ACTIVITY_CHOOSE_IDENTITY = 2 ;
2010-07-21 23:15:28 -04:00
private static final int ACTIVITY_CHOOSE_ACCOUNT = 3 ;
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 " )
* /
private static final Pattern prefix = Pattern . compile ( " ^AW[: \\ s] \\ s* " , Pattern . CASE_INSENSITIVE ) ;
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
/ * *
* 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 ;
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 ;
2009-06-08 23:11:35 -04:00
private TextView mFromView ;
2008-11-01 17:32:06 -04:00
private MultiAutoCompleteTextView mToView ;
private MultiAutoCompleteTextView mCcView ;
private MultiAutoCompleteTextView mBccView ;
private EditText mSubjectView ;
2009-06-08 23:11:35 -04:00
private EditText mSignatureView ;
2008-11-01 17:32:06 -04:00
private EditText mMessageContentView ;
private LinearLayout mAttachments ;
private View mQuotedTextBar ;
private ImageButton mQuotedTextDelete ;
2009-06-08 23:11:35 -04:00
private EditText 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 ;
2010-08-22 05:51:17 -04:00
private PgpData mPgpData = null ;
2009-11-21 17:45:39 -05:00
2009-11-17 16:13:29 -05:00
private String mReferences ;
private String mInReplyTo ;
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
/ * *
* The draft uid of this message . This is used when saving drafts so that the same draft is
* overwritten instead of being created anew . This property is null until the first save .
* /
private String mDraftUid ;
2009-11-24 19:40:29 -05:00
private Handler mHandler = new Handler ( )
{
2008-11-01 17:32:06 -04:00
@Override
2009-11-24 19:40:29 -05:00
public void handleMessage ( android . os . Message msg )
{
switch ( msg . what )
{
case MSG_PROGRESS_ON :
setProgressBarIndeterminateVisibility ( true ) ;
break ;
case MSG_PROGRESS_OFF :
setProgressBarIndeterminateVisibility ( false ) ;
break ;
case MSG_UPDATE_TITLE :
updateTitle ( ) ;
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 ;
default :
super . handleMessage ( msg ) ;
break ;
2008-11-01 17:32:06 -04:00
}
}
} ;
private Listener mListener = new Listener ( ) ;
private EmailAddressAdapter mAddressAdapter ;
private Validator mAddressValidator ;
2010-12-14 14:26:18 -05:00
static class Attachment implements Serializable
2009-11-24 19:40:29 -05:00
{
2008-11-01 17:32:06 -04:00
public String name ;
public String contentType ;
public long size ;
public Uri uri ;
}
/ * *
* Compose a new message using the given account . If account is null the default account
* will be used .
* @param context
* @param account
* /
2009-11-24 19:40:29 -05:00
public static void actionCompose ( Context context , Account account )
{
2010-06-07 20:45:07 -04:00
if ( account = = null )
{
account = Preferences . getPreferences ( context ) . getDefaultAccount ( ) ;
}
2009-11-21 17:45:39 -05:00
Intent i = new Intent ( context , MessageCompose . class ) ;
2010-03-03 23:00:30 -05:00
i . putExtra ( EXTRA_ACCOUNT , account . getUuid ( ) ) ;
2009-11-21 17:45:39 -05:00
context . startActivity ( i ) ;
2008-11-01 17:32:06 -04:00
}
/ * *
* 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
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
* /
public static void actionReply (
2009-11-21 17:45:39 -05:00
Context context ,
Account account ,
Message message ,
2010-07-27 08:10:09 -04:00
boolean replyAll ,
String messageBody )
2009-11-24 19:40:29 -05:00
{
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 ( ) ) ;
2009-11-24 19:40:29 -05:00
if ( replyAll )
{
2008-11-01 17:32:06 -04:00
i . setAction ( ACTION_REPLY_ALL ) ;
2009-11-24 19:40:29 -05:00
}
else
{
2008-11-01 17:32:06 -04:00
i . setAction ( ACTION_REPLY ) ;
}
context . startActivity ( i ) ;
}
/ * *
* 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 ,
String messageBody )
2009-11-24 19:40:29 -05:00
{
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 account
* @param message
* /
2009-11-24 19:40:29 -05:00
public static void actionEditDraft ( Context context , Account account , Message message )
{
2008-11-01 17:32:06 -04:00
Intent i = new Intent ( context , MessageCompose . class ) ;
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_EDIT_DRAFT ) ;
context . startActivity ( i ) ;
}
2009-10-17 23:22:17 -04:00
@Override
2009-11-24 19:40:29 -05:00
public void onCreate ( Bundle savedInstanceState )
{
2008-11-01 17:32:06 -04:00
super . onCreate ( savedInstanceState ) ;
requestWindowFeature ( Window . FEATURE_INDETERMINATE_PROGRESS ) ;
setContentView ( R . layout . message_compose ) ;
2010-07-21 23:15:28 -04:00
final Intent intent = getIntent ( ) ;
mMessageReference = ( MessageReference ) intent . getSerializableExtra ( 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-01-12 18:48:28 -05:00
if ( K9 . DEBUG & & mSourceMessageBody ! = null )
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
if ( mAccount = = null )
{
mAccount = Preferences . getPreferences ( this ) . getDefaultAccount ( ) ;
}
2010-07-21 23:15:28 -04:00
2009-12-27 12:22:44 -05:00
if ( mAccount = = null )
{
/ *
* 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 ;
}
2010-03-22 23:19:12 -04:00
mAddressAdapter = EmailAddressAdapter . getInstance ( this ) ;
2008-11-01 17:32:06 -04:00
mAddressValidator = new EmailAddressValidator ( ) ;
2009-06-08 23:11:35 -04:00
mFromView = ( TextView ) findViewById ( R . id . from ) ;
2008-11-01 17:32:06 -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 ) ;
2009-11-21 17:45:39 -05:00
2009-06-08 23:11:35 -04:00
EditText upperSignature = ( EditText ) findViewById ( R . id . upper_signature ) ;
EditText lowerSignature = ( EditText ) findViewById ( R . id . lower_signature ) ;
2009-11-21 17:45:39 -05:00
2008-11-01 17:32:06 -04:00
mMessageContentView = ( EditText ) findViewById ( R . id . message_content ) ;
2011-01-04 08:25:59 -05:00
mMessageContentView . getInputExtras ( true ) . putBoolean ( " allowEmoji " , true ) ;
2008-11-01 17:32:06 -04:00
mAttachments = ( LinearLayout ) findViewById ( R . id . attachments ) ;
mQuotedTextBar = findViewById ( R . id . quoted_text_bar ) ;
mQuotedTextDelete = ( ImageButton ) findViewById ( R . id . quoted_text_delete ) ;
2009-06-08 23:11:35 -04:00
mQuotedText = ( EditText ) 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
mQuotedHTML . setWebViewClient ( new WebViewClient ( )
{
@Override
public boolean shouldOverrideUrlLoading ( WebView view , String url )
{
return true ;
}
} ) ;
2009-11-24 19:40:29 -05:00
TextWatcher watcher = new TextWatcher ( )
{
2008-11-01 17:32:06 -04:00
public void beforeTextChanged ( CharSequence s , int start ,
2009-11-21 17:45:39 -05:00
int before , int after ) { }
2008-11-01 17:32:06 -04:00
public void onTextChanged ( CharSequence s , int start ,
2009-11-24 19:40:29 -05:00
int before , int count )
{
2008-11-01 17:32:06 -04:00
mDraftNeedsSaving = true ;
}
public void afterTextChanged ( android . text . Editable s ) { }
} ;
2009-11-24 19:40:29 -05:00
TextWatcher sigwatcher = new TextWatcher ( )
{
2009-06-08 23:11:35 -04:00
public void beforeTextChanged ( CharSequence s , int start ,
2009-11-21 17:45:39 -05:00
int before , int after ) { }
2009-06-08 23:11:35 -04:00
public void onTextChanged ( CharSequence s , int start ,
2009-11-24 19:40:29 -05:00
int before , int count )
{
2009-06-08 23:11:35 -04:00
mDraftNeedsSaving = true ;
mSignatureChanged = true ;
}
public void afterTextChanged ( android . text . Editable s ) { }
} ;
2008-11-01 17:32:06 -04:00
mToView . addTextChangedListener ( watcher ) ;
mCcView . addTextChangedListener ( watcher ) ;
mBccView . addTextChangedListener ( watcher ) ;
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
/ *
* We set this to invisible by default . Other methods will turn it back on if it ' s
* needed .
* /
mQuotedTextBar . setVisibility ( View . GONE ) ;
mQuotedText . setVisibility ( View . GONE ) ;
2011-01-12 18:48:28 -05:00
mQuotedHTML . setVisibility ( View . GONE ) ;
2008-11-01 17:32:06 -04:00
mQuotedTextDelete . setOnClickListener ( this ) ;
2009-06-08 23:11:35 -04:00
mFromView . setVisibility ( View . GONE ) ;
2009-11-21 17:45:39 -05:00
2008-11-01 17:32:06 -04:00
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 ) ;
mSubjectView . setOnFocusChangeListener ( this ) ;
2009-11-24 19:40:29 -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
}
2010-11-13 21:27:42 -05:00
final String action = intent . getAction ( ) ;
initFromIntent ( intent ) ;
2009-11-21 17:45:39 -05:00
2009-11-24 19:40:29 -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
2009-11-24 19:40:29 -05:00
if ( mAccount . isSignatureBeforeQuotedText ( ) )
{
2009-06-08 23:11:35 -04:00
mSignatureView = upperSignature ;
lowerSignature . setVisibility ( View . GONE ) ;
2009-11-24 19:40:29 -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
2010-02-08 12:47:00 -05:00
if ( ! mIdentity . getSignatureUse ( ) )
{
mSignatureView . setVisibility ( View . GONE ) ;
}
2009-11-24 19:40:29 -05:00
if ( ! mSourceMessageProcessed )
{
2009-11-16 15:47:27 -05:00
updateFrom ( ) ;
updateSignature ( ) ;
2009-05-13 20:03:19 -04:00
2010-07-21 23:15:28 -04:00
if ( ACTION_REPLY . equals ( action ) | |
2010-07-21 23:40:30 -04:00
ACTION_REPLY_ALL . equals ( action ) | |
ACTION_FORWARD . equals ( action ) | |
ACTION_EDIT_DRAFT . equals ( action ) )
2009-11-24 19:40:29 -05:00
{
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
2009-11-24 19:40:29 -05:00
if ( ! ACTION_EDIT_DRAFT . equals ( action ) )
{
2009-11-16 15:47:27 -05:00
String bccAddress = mAccount . getAlwaysBcc ( ) ;
2010-07-21 23:15:28 -04:00
if ( ( bccAddress ! = null ) & & ! ( " " . equals ( bccAddress ) ) )
2009-11-24 19:40:29 -05:00
{
2010-07-21 23:15:28 -04:00
addAddress ( mBccView , new Address ( bccAddress , " " ) ) ;
2009-11-16 15:47:27 -05:00
}
}
2010-07-21 23:15:28 -04:00
/ *
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
2010-07-21 23:15:28 -04:00
Log . d ( K9 . LOG_TAG , " action = " + action + " , account = " + mMessageReference . accountUuid + " , folder = " + mMessageReference . folderName + " , sourceMessageUid = " + mMessageReference . uid ) ;
* /
if ( ACTION_REPLY . equals ( action ) | |
2010-07-21 23:40:30 -04:00
ACTION_REPLY_ALL . equals ( action ) )
2009-11-24 19:40:29 -05:00
{
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Setting message ANSWERED flag to true " ) ;
2010-07-21 23:15:28 -04:00
2009-11-21 17:45:39 -05:00
// TODO: Really, we should wait until we send the message, but that would require saving the original
// message info along with a Draft copy, in case it is left in Drafts for a while before being sent
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 ( ) ) . setFlag ( account , folderName , new String [ ] { sourceMessageUid } , Flag . ANSWERED , true ) ;
2009-11-16 15:47:27 -05:00
}
updateTitle ( ) ;
}
2009-09-16 23:43:02 -04:00
2010-07-21 23:15:28 -04:00
if ( ACTION_REPLY . equals ( action ) | |
2010-07-21 23:40:30 -04:00
ACTION_REPLY_ALL . equals ( action ) | |
ACTION_EDIT_DRAFT . equals ( action ) )
2009-11-24 19:40:29 -05:00
{
2009-10-17 23:22:17 -04:00
//change focus to message body.
mMessageContentView . requestFocus ( ) ;
}
2009-11-16 15:47:27 -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 ) ;
initializeCrypto ( ) ;
2010-08-22 05:51:17 -04:00
final CryptoProvider crypto = mAccount . getCryptoProvider ( ) ;
if ( crypto . isAvailable ( this ) )
2010-07-27 08:10:09 -04:00
{
mEncryptLayout . setVisibility ( View . VISIBLE ) ;
mCryptoSignatureCheckbox . setOnClickListener ( new OnClickListener ( )
{
@Override
public void onClick ( View v )
{
CheckBox checkBox = ( CheckBox ) v ;
if ( checkBox . isChecked ( ) )
{
mPreventDraftSaving = true ;
2010-08-22 05:51:17 -04:00
if ( ! crypto . selectSecretKey ( MessageCompose . this , mPgpData ) )
2010-07-27 08:10:09 -04:00
{
mPreventDraftSaving = false ;
}
checkBox . setChecked ( false ) ;
}
else
{
2010-08-22 05:51:17 -04:00
mPgpData . setSignatureKeyId ( 0 ) ;
2010-07-27 08:10:09 -04:00
updateEncryptLayout ( ) ;
}
}
} ) ;
if ( mAccount . getCryptoAutoSignature ( ) )
{
2010-08-22 05:51:17 -04:00
long ids [ ] = crypto . getSecretKeyIdsFromEmail ( this , mIdentity . getEmail ( ) ) ;
2010-07-27 08:10:09 -04: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 ] ) ) ;
2010-07-27 08:10:09 -04: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 ( ) ;
}
else
{
mEncryptLayout . setVisibility ( View . GONE ) ;
}
2009-11-16 15:47:27 -05:00
mDraftNeedsSaving = false ;
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 .
*
* @param intent The ( external ) intent that started the activity .
* /
private void initFromIntent ( final Intent intent )
{
final String action = intent . getAction ( ) ;
if ( Intent . ACTION_VIEW . equals ( action ) | | Intent . ACTION_SENDTO . equals ( action ) )
{
/ *
* Someone has clicked a mailto : link . The address is in the URI .
* /
if ( intent . getData ( ) ! = null )
{
Uri uri = intent . getData ( ) ;
if ( " mailto " . equals ( uri . getScheme ( ) ) )
{
initializeFromMailto ( uri ) ;
}
}
/ *
* Note : According to the documenation ACTION_VIEW and ACTION_SENDTO
* don ' t accept EXTRA_ * parameters . Contrary to the AOSP Email application
* we don ' t accept those EXTRAs .
* Dear developer , if your application is using those EXTRAs you ' re doing
* it wrong ! So go fix your program or get AOSP to change the documentation .
* /
}
//TODO: Use constant Intent.ACTION_SEND_MULTIPLE once we drop Android 1.5 support
else if ( Intent . ACTION_SEND . equals ( action ) | |
" android.intent.action.SEND_MULTIPLE " . equals ( action ) )
{
/ *
* Note : Here we allow a slight deviation from the documentated behavior .
* 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 ) ;
if ( text ! = null )
{
mMessageContentView . setText ( text ) ;
}
String type = intent . getType ( ) ;
if ( Intent . ACTION_SEND . equals ( action ) )
{
Uri stream = ( Uri ) intent . getParcelableExtra ( Intent . EXTRA_STREAM ) ;
if ( stream ! = null )
{
addAttachment ( stream , type ) ;
}
}
else
{
ArrayList < Parcelable > list = intent . getParcelableArrayListExtra ( Intent . EXTRA_STREAM ) ;
if ( list ! = null )
{
for ( Parcelable parcelable : list )
{
Uri stream = ( Uri ) parcelable ;
if ( stream ! = null )
{
addAttachment ( stream , type ) ;
}
}
}
}
String subject = intent . getStringExtra ( Intent . EXTRA_SUBJECT ) ;
if ( subject ! = null )
{
mSubjectView . setText ( subject ) ;
}
String [ ] extraEmail = intent . getStringArrayExtra ( Intent . EXTRA_EMAIL ) ;
String [ ] extraCc = intent . getStringArrayExtra ( Intent . EXTRA_CC ) ;
String [ ] extraBcc = intent . getStringArrayExtra ( Intent . EXTRA_BCC ) ;
if ( extraEmail ! = null )
{
setRecipients ( mToView , Arrays . asList ( extraEmail ) ) ;
}
boolean ccOrBcc = false ;
if ( extraCc ! = null )
{
ccOrBcc | = setRecipients ( mCcView , Arrays . asList ( extraCc ) ) ;
}
if ( extraBcc ! = null )
{
ccOrBcc | = setRecipients ( mBccView , Arrays . asList ( extraBcc ) ) ;
}
if ( ccOrBcc )
{
// Display CC and BCC text fields if CC or BCC recipients were set by the intent.
onAddCcBcc ( ) ;
}
}
}
private boolean setRecipients ( TextView view , List < String > recipients )
{
boolean recipientAdded = false ;
if ( recipients ! = null )
{
StringBuffer addressList = new StringBuffer ( ) ;
for ( String recipient : recipients )
{
addressList . append ( recipient ) ;
addressList . append ( " , " ) ;
recipientAdded = true ;
}
view . setText ( addressList ) ;
}
return recipientAdded ;
}
2010-07-27 08:10:09 -04:00
private void initializeCrypto ( )
{
2010-08-22 05:51:17 -04:00
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 .
* /
public void updateEncryptLayout ( )
{
2010-08-22 05:51:17 -04:00
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 ) ;
}
else
{
// 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 ( ) ;
2010-07-27 08:10:09 -04: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
}
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 ] ) ;
if ( chunks . length > 1 )
{
mCryptoSignatureUserIdRest . setText ( " < " + chunks [ 1 ] ) ;
}
}
}
}
2010-04-16 08:20:10 -04:00
@Override
2009-11-24 19:40:29 -05:00
public void onResume ( )
{
2008-11-01 17:32:06 -04:00
super . onResume ( ) ;
MessagingController . getInstance ( getApplication ( ) ) . addListener ( mListener ) ;
}
2010-04-16 08:20:10 -04:00
@Override
2009-11-24 19:40:29 -05:00
public void onPause ( )
{
2008-11-01 17:32:06 -04:00
super . onPause ( ) ;
2010-07-12 10:57:42 -04:00
saveIfNeeded ( ) ;
2008-11-01 17:32:06 -04:00
MessagingController . getInstance ( getApplication ( ) ) . removeListener ( mListener ) ;
}
/ * *
* 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
2009-11-24 19:40:29 -05:00
protected void onSaveInstanceState ( Bundle outState )
{
2008-11-01 17:32:06 -04:00
super . onSaveInstanceState ( outState ) ;
2010-07-12 10:57:42 -04:00
saveIfNeeded ( ) ;
2008-11-01 17:32:06 -04:00
ArrayList < Uri > attachments = new ArrayList < Uri > ( ) ;
2009-11-24 19:40:29 -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 ( ) ;
attachments . add ( attachment . uri ) ;
}
outState . putParcelableArrayList ( STATE_KEY_ATTACHMENTS , attachments ) ;
outState . putBoolean ( STATE_KEY_CC_SHOWN , mCcView . getVisibility ( ) = = View . VISIBLE ) ;
outState . putBoolean ( STATE_KEY_BCC_SHOWN , mBccView . getVisibility ( ) = = View . VISIBLE ) ;
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
outState . putBoolean ( STATE_KEY_QUOTED_TEXT_SHOWN , mQuotedTextBar . getVisibility ( ) = = View . VISIBLE ) ;
2008-11-01 17:32:06 -04:00
outState . putBoolean ( STATE_KEY_SOURCE_MESSAGE_PROCED , mSourceMessageProcessed ) ;
outState . putString ( STATE_KEY_DRAFT_UID , mDraftUid ) ;
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 ) ;
2008-11-01 17:32:06 -04:00
}
@Override
2009-11-24 19:40:29 -05:00
protected void onRestoreInstanceState ( Bundle savedInstanceState )
{
2008-11-01 17:32:06 -04:00
super . onRestoreInstanceState ( savedInstanceState ) ;
2011-01-18 20:21:27 -05:00
ArrayList < Parcelable > attachments = savedInstanceState . getParcelableArrayList ( STATE_KEY_ATTACHMENTS ) ;
2008-11-01 17:32:06 -04:00
mAttachments . removeAllViews ( ) ;
2009-11-24 19:40:29 -05:00
for ( Parcelable p : attachments )
{
2008-11-01 17:32:06 -04:00
Uri uri = ( Uri ) p ;
addAttachment ( uri ) ;
}
2011-01-12 18:48:28 -05:00
mCcView . setVisibility ( savedInstanceState . getBoolean ( STATE_KEY_CC_SHOWN ) ? View . VISIBLE : View . GONE ) ;
mBccView . setVisibility ( savedInstanceState . getBoolean ( STATE_KEY_BCC_SHOWN ) ? View . VISIBLE : View . GONE ) ;
if ( mAccount . getMessageFormat ( ) = = MessageFormat . HTML )
{
mQuotedHtmlContent = ( InsertableHtmlContent ) savedInstanceState . getSerializable ( STATE_KEY_HTML_QUOTE ) ;
mQuotedTextBar . setVisibility ( savedInstanceState . getBoolean ( STATE_KEY_QUOTED_TEXT_SHOWN ) ? View . VISIBLE : View . GONE ) ;
mQuotedHTML . setVisibility ( savedInstanceState . getBoolean ( STATE_KEY_QUOTED_TEXT_SHOWN ) ? View . VISIBLE : View . GONE ) ;
2011-01-24 22:56:19 -05:00
if ( mQuotedHtmlContent ! = null & & mQuotedHtmlContent . getQuotedContent ( ) ! = null )
2011-01-12 18:48:28 -05:00
{
mQuotedHTML . loadDataWithBaseURL ( " http:// " , mQuotedHtmlContent . getQuotedContent ( ) , " text/html " , " utf-8 " , null ) ;
}
}
else
{
mQuotedTextBar . setVisibility ( savedInstanceState . getBoolean ( STATE_KEY_QUOTED_TEXT_SHOWN ) ? View . VISIBLE : View . GONE ) ;
mQuotedText . setVisibility ( savedInstanceState . getBoolean ( STATE_KEY_QUOTED_TEXT_SHOWN ) ? View . VISIBLE : View . GONE ) ;
}
2008-11-01 17:32:06 -04:00
mDraftUid = savedInstanceState . getString ( STATE_KEY_DRAFT_UID ) ;
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 ) ;
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
2008-11-01 17:32:06 -04:00
mDraftNeedsSaving = false ;
}
2009-11-24 19:40:29 -05:00
private void updateTitle ( )
{
if ( mSubjectView . getText ( ) . length ( ) = = 0 )
{
2008-11-01 17:32:06 -04:00
setTitle ( R . string . compose_title ) ;
2009-11-24 19:40:29 -05:00
}
else
{
2008-11-01 17:32:06 -04:00
setTitle ( mSubjectView . getText ( ) . toString ( ) ) ;
}
}
2009-11-24 19:40:29 -05:00
public void onFocusChange ( View view , boolean focused )
{
if ( ! focused )
{
2008-11-01 17:32:06 -04:00
updateTitle ( ) ;
}
}
2009-11-24 19:40:29 -05:00
private void addAddresses ( MultiAutoCompleteTextView view , Address [ ] addresses )
{
if ( addresses = = null )
{
2008-11-01 17:32:06 -04:00
return ;
}
2009-11-24 19:40:29 -05:00
for ( Address address : addresses )
{
2008-11-01 17:32:06 -04:00
addAddress ( view , address ) ;
}
}
2009-11-24 19:40:29 -05:00
private void addAddress ( MultiAutoCompleteTextView view , Address address )
{
2008-11-01 17:32:06 -04:00
view . append ( address + " , " ) ;
}
2009-11-24 19:40:29 -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
}
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-01-12 18:48:28 -05:00
private TextBody buildText ( boolean isDraft )
2010-07-27 08:10:09 -04:00
{
2010-08-30 17:27:07 -04:00
boolean replyAfterQuote = false ;
String action = getIntent ( ) . getAction ( ) ;
if ( mAccount . isReplyAfterQuote ( ) & &
( ACTION_REPLY . equals ( action ) | | ACTION_REPLY_ALL . equals ( action ) ) )
{
replyAfterQuote = true ;
}
2010-07-27 08:10:09 -04:00
String text = mMessageContentView . getText ( ) . toString ( ) ;
2011-01-12 18:48:28 -05:00
// Handle HTML separate from the rest of the text content. HTML mode doesn't allow signature after the quoted
// text, nor does it allow reply after quote. Users who want that functionality will need to stick with text
// mode.
if ( mAccount . getMessageFormat ( ) = = MessageFormat . HTML )
2010-07-27 08:10:09 -04:00
{
2011-01-12 18:48:28 -05:00
// Add the signature.
if ( ! isDraft )
2010-08-30 17:27:07 -04:00
{
2011-01-12 18:48:28 -05:00
text = appendSignature ( text ) ;
}
text = HtmlConverter . textToHtmlFragment ( text ) ;
// Insert it into the existing content object.
if ( K9 . DEBUG & & mQuotedHtmlContent ! = null )
Log . d ( K9 . LOG_TAG , " insertable: " + mQuotedHtmlContent . toDebugString ( ) ) ;
if ( mQuotedHtmlContent ! = null )
{
// Remove the quoted part if it's no longer visible.
if ( mQuotedTextBar . getVisibility ( ) ! = View . VISIBLE )
{
mQuotedHtmlContent . clearQuotedContent ( ) ;
}
2011-01-24 22:56:19 -05:00
mQuotedHtmlContent . setUserContent ( text ) ;
// Set the insertion location based upon our reply after quote setting. Reply after
// quote makes no sense for HEADER style replies. In addition, 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 ( mAccount . getQuoteStyle ( ) = = QuoteStyle . PREFIX & & replyAfterQuote )
2011-01-12 18:48:28 -05:00
{
2011-01-24 22:56:19 -05:00
mQuotedHtmlContent . setInsertionLocation ( InsertableHtmlContent . InsertionLocation . AFTER_QUOTE ) ;
if ( ! isDraft )
{
text = " <br><br> " + text ;
}
}
else
{
mQuotedHtmlContent . setInsertionLocation ( InsertableHtmlContent . InsertionLocation . BEFORE_QUOTE ) ;
if ( ! isDraft )
{
text + = " <br> " ;
}
2011-01-12 18:48:28 -05:00
}
// All done. Build the body.
TextBody body = new TextBody ( mQuotedHtmlContent . toString ( ) ) ;
// Save length of the body and its offset. This is used when thawing drafts.
body . setComposedMessageLength ( text . length ( ) ) ;
2011-01-24 22:56:19 -05:00
body . setComposedMessageOffset ( mQuotedHtmlContent . getInsertionPoint ( ) ) ;
2011-01-12 18:48:28 -05:00
return body ;
2010-08-30 17:27:07 -04:00
}
else
{
2011-01-12 18:48:28 -05:00
TextBody body = new TextBody ( text ) ;
body . setComposedMessageLength ( text . length ( ) ) ;
// Not in reply to anything so the message starts at the beginning (0).
body . setComposedMessageOffset ( 0 ) ;
return body ;
2010-08-30 17:27:07 -04:00
}
2010-07-27 08:10:09 -04:00
}
2011-01-12 18:48:28 -05:00
else if ( mAccount . getMessageFormat ( ) = = MessageFormat . TEXT )
{
// Capture composed message length before we start attaching quoted parts and signatures.
Integer composedMessageLength = text . length ( ) ;
Integer composedMessageOffset = 0 ;
// Placing the signature before the quoted text does not make sense if replyAfterQuote is true.
if ( ! replyAfterQuote & & ! isDraft & & mAccount . isSignatureBeforeQuotedText ( ) )
{
text = appendSignature ( text ) ;
}
if ( mQuotedTextBar . getVisibility ( ) = = View . VISIBLE )
{
if ( replyAfterQuote )
{
composedMessageOffset = mQuotedText . getText ( ) . toString ( ) . length ( ) + " \ n " . length ( ) ;
text = mQuotedText . getText ( ) . toString ( ) + " \ n " + text ;
}
else
{
text + = " \ n \ n " + mQuotedText . getText ( ) . toString ( ) ;
}
}
// Note: If user has selected reply after quote AND signature before quote, ignore the
// latter setting and append the signature at the end.
if ( ! isDraft & & ( ! mAccount . isSignatureBeforeQuotedText ( ) | | replyAfterQuote ) )
{
text = appendSignature ( text ) ;
}
// Build the body.
TextBody body = new TextBody ( text ) ;
body . setComposedMessageLength ( composedMessageLength ) ;
body . setComposedMessageOffset ( composedMessageOffset ) ;
2010-07-27 08:10:09 -04:00
2011-01-12 18:48:28 -05:00
return body ;
}
else
2010-07-27 08:10:09 -04:00
{
2011-01-12 18:48:28 -05:00
// Shouldn't happen.
return new TextBody ( " " ) ;
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
* /
private MimeMessage createMessage ( boolean isDraft ) throws MessagingException
2009-11-24 19:40:29 -05:00
{
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-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 ( ) ;
if ( replyTo ! = null )
{
message . setReplyTo ( new Address [ ] { new Address ( replyTo ) } ) ;
}
2009-11-24 19:40:29 -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
2009-11-24 19:40:29 -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.
// TODO FIXME - body can be either an HTML or Text part, depending on whether we're in HTML mode or not. Should probably fix this so we don't mix up html and text parts.
TextBody body = null ;
2010-08-22 05:51:17 -04:00
if ( mPgpData . getEncryptedData ( ) ! = null )
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
String text = mPgpData . getEncryptedData ( ) ;
body = new TextBody ( text ) ;
}
else
{
body = buildText ( isDraft ) ;
}
final boolean hasAttachments = mAttachments . getChildCount ( ) > 0 ;
if ( mAccount . getMessageFormat ( ) = = MessageFormat . HTML )
{
// 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 " ) ) ;
composedMimeMessage . addBodyPart ( new MimeBodyPart ( new TextBody ( HtmlConverter . htmlToText ( body . getText ( ) ) ) , " text/plain " ) ) ;
if ( hasAttachments )
{
// 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 ) ;
}
else
{
// If no attachments, our multipart/alternative part is the only one we need.
message . setBody ( composedMimeMessage ) ;
}
2009-06-08 23:11:35 -04:00
}
2010-07-27 08:10:09 -04:00
else
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
// Text-only message.
if ( hasAttachments )
{
MimeMultipart mp = new MimeMultipart ( ) ;
mp . addBodyPart ( new MimeBodyPart ( body , " text/plain " ) ) ;
addAttachmentsToMessage ( mp ) ;
message . setBody ( mp ) ;
}
else
{
// 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.
if ( isDraft )
{
// Add the identity to the message.
message . addHeader ( K9 . IDENTITY_HEADER , buildIdentityHeader ( body ) ) ;
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
* /
private void addAttachmentsToMessage ( final MimeMultipart mp ) throws MessagingException
{
for ( int i = 0 , count = mAttachments . getChildCount ( ) ; i < count ; i + + )
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
Attachment attachment = ( Attachment ) mAttachments . getChildAt ( i ) . getTag ( ) ;
MimeBodyPart bp = new MimeBodyPart (
new LocalStore . LocalAttachmentBody ( attachment . uri , getApplication ( ) ) ) ;
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
* /
2011-01-12 18:48:28 -05:00
bp . addHeader ( MimeHeader . HEADER_CONTENT_TYPE , String . format ( " %s; \ n name= \" %s \" " ,
attachment . contentType ,
EncoderUtil . encodeIfNecessary ( attachment . name ,
EncoderUtil . Usage . WORD_ENTITY , 7 ) ) ) ;
2008-11-01 17:32:06 -04:00
2011-01-12 18:48:28 -05:00
bp . addHeader ( MimeHeader . HEADER_CONTENT_TRANSFER_ENCODING , " base64 " ) ;
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 (
" attachment; \ n filename= \" %s \" ; \ n size=%d " ,
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-01-13 20:37:52 -05:00
private enum IdentityField
{
2011-01-12 18:48:28 -05:00
LENGTH ( " l " ) ,
OFFSET ( " o " ) ,
MESSAGE_FORMAT ( " f " ) ,
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.
ORIGINAL_MESSAGE ( " m " ) ;
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-01-13 20:37:52 -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-01-13 20:37:52 -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
/ * *
* Get the list of IdentityFields that should be integer values . These values are sanity
* checked for integer - ness during decoding .
* @return
* /
2011-01-13 20:37:52 -05:00
public static IdentityField [ ] getIntegerFields ( )
{
2011-01-12 18:48:28 -05:00
return new IdentityField [ ] { LENGTH , OFFSET } ;
}
}
/ * *
* 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 .
* @return Identity string .
* /
2011-01-13 20:37:52 -05:00
private String buildIdentityHeader ( final TextBody body )
{
2011-01-12 18:48:28 -05:00
Uri . Builder uri = new Uri . Builder ( ) ;
2011-01-13 20:37:52 -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-01-13 20:37:52 -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 ) ) ;
}
// Save the message format for this offset.
uri . appendQueryParameter ( IdentityField . MESSAGE_FORMAT . value ( ) , mAccount . getMessageFormat ( ) . name ( ) ) ;
// If we're not using the standard identity of signature, append it on to the identity blob.
if ( mSignatureChanged )
{
uri . appendQueryParameter ( IdentityField . SIGNATURE . value ( ) , mSignatureView . getText ( ) . toString ( ) ) ;
}
if ( mIdentityChanged )
{
uri . appendQueryParameter ( IdentityField . NAME . value ( ) , mIdentity . getName ( ) ) ;
uri . appendQueryParameter ( IdentityField . EMAIL . value ( ) , mIdentity . getEmail ( ) ) ;
}
// Tag this is as a "new style" identity. ! is an impossible value in base64 encoding, so we
// use that to determine which version we're in.
String k9identity = " ! " + uri . build ( ) . getEncodedQuery ( ) ;
if ( K9 . DEBUG )
{
Log . d ( K9 . LOG_TAG , " Generated identity: " + k9identity ) ;
}
return k9identity ;
}
/ * *
* Parse an identity string . Handles both legacy and new ( ! ) style identities .
* @param identityString
* @return
* /
private Map < IdentityField , String > parseIdentityHeader ( final String identityString )
{
Map < IdentityField , String > identity = new HashMap < IdentityField , String > ( ) ;
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Decoding identity: " + identityString ) ;
if ( identityString = = null | | identityString . length ( ) < 1 )
{
return identity ;
}
if ( identityString . charAt ( 0 ) = = '!' & & identityString . length ( ) > 2 )
{
Uri . Builder builder = new Uri . Builder ( ) ;
builder . encodedQuery ( identityString . substring ( 1 ) ) ; // Need to cut off the ! at the beginning.
Uri uri = builder . build ( ) ;
for ( IdentityField key : IdentityField . values ( ) )
{
String value = uri . getQueryParameter ( key . value ( ) ) ;
if ( value ! = null )
{
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.
for ( IdentityField key : IdentityField . getIntegerFields ( ) )
{
if ( identity . get ( key ) ! = null )
{
try
{
Integer . parseInt ( identity . get ( key ) ) ;
2011-01-13 20:37:52 -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 ) ) ;
}
}
}
2009-11-24 19:40:29 -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.
if ( tokens . hasMoreTokens ( ) )
{
String bodyLengthS = Utility . base64Decode ( tokens . nextToken ( ) ) ;
try
{
identity . put ( IdentityField . LENGTH , Integer . valueOf ( bodyLengthS ) . toString ( ) ) ;
2011-01-13 20:37:52 -05:00
}
catch ( Exception e )
2011-01-12 18:48:28 -05:00
{
Log . e ( K9 . LOG_TAG , " Unable to parse bodyLength ' " + bodyLengthS + " ' " ) ;
}
}
if ( tokens . hasMoreTokens ( ) )
{
identity . put ( IdentityField . SIGNATURE , Utility . base64Decode ( tokens . nextToken ( ) ) ) ;
}
if ( tokens . hasMoreTokens ( ) )
{
identity . put ( IdentityField . NAME , Utility . base64Decode ( tokens . nextToken ( ) ) ) ;
}
if ( tokens . hasMoreTokens ( ) )
{
identity . put ( IdentityField . EMAIL , 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
2009-11-24 19:40:29 -05:00
private String appendSignature ( String text )
{
2010-02-08 12:47:00 -05:00
if ( mIdentity . getSignatureUse ( ) )
2009-11-24 19:40:29 -05:00
{
2010-02-08 12:47:00 -05:00
String signature = mSignatureView . getText ( ) . toString ( ) ;
if ( signature ! = null & & ! signature . contentEquals ( " " ) )
{
text + = " \ n " + signature ;
}
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
2010-07-21 23:40:14 -04:00
private void sendMessage ( )
2009-11-24 19:40:29 -05:00
{
2010-07-21 23:40:22 -04:00
new SendMessageTask ( ) . execute ( ) ;
2010-07-21 23:40:14 -04:00
}
private void saveMessage ( )
{
2010-07-21 23:40:22 -04:00
new SaveMessageTask ( ) . execute ( ) ;
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
private void saveIfNeeded ( )
{
2010-08-22 05:51:17 -04:00
if ( ! mDraftNeedsSaving | | mPreventDraftSaving | | mPgpData . hasEncryptionKeys ( ) )
2009-11-24 19:40:29 -05:00
{
2008-11-01 17:32:06 -04:00
return ;
}
2010-07-27 08:10:09 -04:00
mDraftNeedsSaving = false ;
saveMessage ( ) ;
}
public void onEncryptionKeySelectionDone ( )
{
2010-08-22 05:51:17 -04:00
if ( mPgpData . hasEncryptionKeys ( ) )
2010-07-27 08:10:09 -04:00
{
onSend ( ) ;
}
else
{
Toast . makeText ( this , R . string . send_aborted , Toast . LENGTH_SHORT ) . show ( ) ;
}
}
public void onEncryptDone ( )
{
2010-08-22 05:51:17 -04:00
if ( mPgpData . getEncryptedData ( ) ! = null )
2010-07-27 08:10:09 -04:00
{
onSend ( ) ;
}
else
{
Toast . makeText ( this , R . string . send_aborted , Toast . LENGTH_SHORT ) . show ( ) ;
}
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -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 ;
}
2010-08-22 05:51:17 -04:00
if ( mEncryptCheckbox . isChecked ( ) & & ! mPgpData . hasEncryptionKeys ( ) )
2010-07-27 08:10:09 -04:00
{
// key selection before encryption
String emails = " " ;
Address [ ] [ ] addresses = new Address [ ] [ ] { getAddresses ( mToView ) ,
getAddresses ( mCcView ) ,
getAddresses ( mBccView )
} ;
for ( Address [ ] addressArray : addresses )
{
for ( Address address : addressArray )
{
if ( emails . length ( ) ! = 0 )
{
emails + = " , " ;
}
emails + = address . getAddress ( ) ;
}
}
if ( emails . length ( ) ! = 0 )
{
emails + = " , " ;
}
emails + = mIdentity . getEmail ( ) ;
mPreventDraftSaving = true ;
2010-08-22 05:51:17 -04:00
if ( ! mAccount . getCryptoProvider ( ) . selectEncryptionKeys ( MessageCompose . this , emails , mPgpData ) )
2010-07-27 08:10:09 -04:00
{
mPreventDraftSaving = false ;
}
return ;
}
2010-08-22 05:51:17 -04:00
if ( mPgpData . hasEncryptionKeys ( ) | | mPgpData . hasSignatureKey ( ) )
2010-07-27 08:10:09 -04:00
{
2010-08-22 05:51:17 -04:00
if ( mPgpData . getEncryptedData ( ) = = null )
2010-07-27 08:10:09 -04:00
{
2011-01-12 18:48:28 -05:00
String text = buildText ( false ) . getText ( ) ;
2010-07-27 08:10:09 -04:00
mPreventDraftSaving = true ;
2010-08-22 05:51:17 -04:00
if ( ! mAccount . getCryptoProvider ( ) . encrypt ( this , text , mPgpData ) )
2010-07-27 08:10:09 -04:00
{
mPreventDraftSaving = false ;
}
return ;
}
}
2010-07-21 23:40:14 -04:00
sendMessage ( ) ;
2008-11-01 17:32:06 -04:00
mDraftNeedsSaving = false ;
finish ( ) ;
}
2009-11-24 19:40:29 -05:00
private void onDiscard ( )
{
if ( mDraftUid ! = null )
{
2010-03-03 23:00:30 -05:00
MessagingController . getInstance ( getApplication ( ) ) . deleteDraft ( mAccount , mDraftUid ) ;
mDraftUid = null ;
2009-10-17 23:34:54 -04:00
}
2008-11-01 17:32:06 -04:00
mHandler . sendEmptyMessage ( MSG_DISCARDED_DRAFT ) ;
mDraftNeedsSaving = false ;
finish ( ) ;
}
2009-11-24 19:40:29 -05:00
private void onSave ( )
{
2009-11-16 15:47:27 -05:00
mDraftNeedsSaving = true ;
2008-11-01 17:32:06 -04:00
saveIfNeeded ( ) ;
finish ( ) ;
}
2009-11-24 19:40:29 -05:00
private void onAddCcBcc ( )
{
2008-11-01 17:32:06 -04:00
mCcView . setVisibility ( View . VISIBLE ) ;
mBccView . setVisibility ( View . VISIBLE ) ;
}
/ * *
* Kick off a picker for whatever kind of MIME types we ' ll accept and let Android take over .
* /
2009-11-24 19:40:29 -05:00
private void onAddAttachment ( )
2010-05-02 14:24:33 -04:00
{
if ( K9 . isGalleryBuggy ( ) )
{
if ( K9 . useGalleryBugWorkaround ( ) )
{
Toast . makeText ( MessageCompose . this ,
2010-05-11 22:51:59 -04:00
getString ( R . string . message_compose_use_workaround ) ,
Toast . LENGTH_LONG ) . show ( ) ;
2010-05-02 14:24:33 -04:00
}
else
{
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 .
* /
private void onAddAttachment2 ( final String mime_type )
2009-11-24 19:40:29 -05:00
{
2010-08-22 05:51:17 -04:00
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 ) ;
i . addCategory ( Intent . CATEGORY_OPENABLE ) ;
2010-05-02 14:24:33 -04:00
i . setType ( mime_type ) ;
2008-11-01 17:32:06 -04:00
startActivityForResult ( Intent . createChooser ( i , null ) , ACTIVITY_REQUEST_PICK_ATTACHMENT ) ;
}
2009-11-24 19:40:29 -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
}
2010-11-13 21:27:42 -05:00
private void addAttachment ( Uri uri , String contentType )
2009-11-24 19:40:29 -05:00
{
2010-11-13 21:27:42 -05:00
long size = - 1 ;
String name = null ;
2008-11-01 17:32:06 -04:00
ContentResolver contentResolver = getContentResolver ( ) ;
2010-11-13 21:27:42 -05:00
Cursor metadataCursor = contentResolver . query (
uri ,
new String [ ] { OpenableColumns . DISPLAY_NAME , OpenableColumns . SIZE } ,
null ,
null ,
null ) ;
2008-11-01 17:32:06 -04:00
2010-11-13 21:27:42 -05:00
if ( metadataCursor ! = null )
2009-11-24 19:40:29 -05:00
{
2010-11-13 21:27:42 -05:00
try
2009-11-24 19:40:29 -05:00
{
2010-11-13 21:27:42 -05:00
if ( metadataCursor . moveToFirst ( ) )
2009-11-24 19:40:29 -05:00
{
2010-11-13 21:27:42 -05:00
name = metadataCursor . getString ( 0 ) ;
size = metadataCursor . getInt ( 1 ) ;
2008-11-01 17:32:06 -04:00
}
}
2010-11-13 21:27:42 -05:00
finally
{
metadataCursor . close ( ) ;
}
2008-11-01 17:32:06 -04:00
}
2010-11-13 21:27:42 -05:00
if ( name = = null )
2009-11-24 19:40:29 -05:00
{
2010-11-13 21:27:42 -05:00
name = uri . getLastPathSegment ( ) ;
2008-11-01 17:32:06 -04:00
}
2010-11-13 21:27:42 -05:00
if ( ( contentType = = null ) | | ( contentType . indexOf ( '*' ) ! = - 1 ) )
{
contentType = contentResolver . getType ( uri ) ;
}
2009-11-24 19:40:29 -05:00
if ( contentType = = null )
{
2010-11-13 21:27:42 -05:00
contentType = MimeUtility . getMimeTypeByExtension ( name ) ;
2009-11-16 15:51:34 -05:00
}
2010-11-13 21:27:42 -05:00
if ( size < = 0 )
2010-01-28 01:25:10 -05:00
{
String uriString = uri . toString ( ) ;
if ( uriString . startsWith ( " file:// " ) )
{
Log . v ( K9 . LOG_TAG , uriString . substring ( " file:// " . length ( ) ) ) ;
File f = new File ( uriString . substring ( " file:// " . length ( ) ) ) ;
2010-11-13 21:27:42 -05:00
size = f . length ( ) ;
2010-01-28 01:25:10 -05:00
}
2010-04-29 00:59:14 -04:00
else
{
2010-01-28 01:25:10 -05:00
Log . v ( K9 . LOG_TAG , " Not a file: " + uriString ) ;
}
}
2010-04-29 00:59:14 -04:00
else
{
2010-11-13 21:27:42 -05:00
Log . v ( K9 . LOG_TAG , " old attachment.size: " + size ) ;
2010-01-28 01:25:10 -05:00
}
2010-11-13 21:27:42 -05:00
Log . v ( K9 . LOG_TAG , " new attachment.size: " + size ) ;
2010-01-28 01:25:10 -05:00
2010-11-13 21:27:42 -05:00
Attachment attachment = new Attachment ( ) ;
attachment . uri = uri ;
attachment . contentType = contentType ;
attachment . name = name ;
attachment . size = size ;
2010-10-05 02:03:51 -04:00
2009-11-24 19:40:29 -05:00
View view = getLayoutInflater ( ) . inflate ( R . layout . message_compose_attachment , mAttachments , false ) ;
2008-11-01 17:32:06 -04:00
TextView nameView = ( TextView ) view . findViewById ( R . id . attachment_name ) ;
ImageButton delete = ( ImageButton ) view . findViewById ( R . id . attachment_delete ) ;
nameView . setText ( attachment . name ) ;
delete . setOnClickListener ( this ) ;
delete . setTag ( view ) ;
view . setTag ( attachment ) ;
mAttachments . addView ( view ) ;
}
@Override
2009-11-24 19:40:29 -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 ;
2010-08-22 05:51:17 -04: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 ;
2009-11-24 19:40:29 -05:00
if ( data = = null )
{
2008-11-01 17:32:06 -04:00
return ;
}
2009-11-24 19:40:29 -05:00
switch ( requestCode )
{
case ACTIVITY_REQUEST_PICK_ATTACHMENT :
addAttachment ( data . getData ( ) ) ;
mDraftNeedsSaving = true ;
break ;
case ACTIVITY_CHOOSE_IDENTITY :
onIdentityChosen ( data ) ;
break ;
2010-07-21 23:15:28 -04:00
case ACTIVITY_CHOOSE_ACCOUNT :
onAccountChosen ( data ) ;
break ;
2009-11-21 17:45:39 -05:00
}
2009-06-08 23:11:35 -04:00
}
2010-07-21 23:15:28 -04:00
private void onAccountChosen ( final Intent intent )
{
final Bundle extras = intent . getExtras ( ) ;
final String uuid = extras . getString ( ChooseAccount . EXTRA_ACCOUNT ) ;
final Identity identity = ( Identity ) extras . getSerializable ( ChooseAccount . EXTRA_IDENTITY ) ;
final Account account = Preferences . getPreferences ( this ) . getAccount ( uuid ) ;
if ( ! mAccount . equals ( account ) )
{
if ( K9 . DEBUG )
{
Log . v ( K9 . LOG_TAG , " Switching account from " + mAccount + " to " + account ) ;
}
// on draft edit, make sure we don't keep previous message UID
if ( ACTION_EDIT_DRAFT . equals ( getIntent ( ) . getAction ( ) ) )
{
mMessageReference = null ;
}
// test whether there is something to save
if ( mDraftNeedsSaving | | ( mDraftUid ! = null ) )
{
final String previousDraftUid = mDraftUid ;
final Account previousAccount = mAccount ;
// make current message appear as new
mDraftUid = null ;
// actual account switch
mAccount = account ;
if ( K9 . DEBUG )
{
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
if ( previousDraftUid ! = null )
{
if ( K9 . DEBUG )
{
Log . v ( K9 . LOG_TAG , " Account switch, deleting draft from previous account: "
2010-07-21 23:40:14 -04:00
+ previousDraftUid ) ;
2010-07-21 23:15:28 -04:00
}
MessagingController . getInstance ( getApplication ( ) ) . deleteDraft ( previousAccount ,
previousDraftUid ) ;
}
}
else
{
mAccount = account ;
}
// not sure how to handle mFolder, mSourceMessage?
}
switchToIdentity ( identity ) ;
}
2009-11-24 19:40:29 -05:00
private void onIdentityChosen ( Intent intent )
{
2010-11-30 22:07:28 -05:00
Bundle bundle = intent . getExtras ( ) ;
2011-01-12 18:48:28 -05:00
switchToIdentity ( ( Identity ) bundle . getSerializable ( ChooseIdentity . EXTRA_IDENTITY ) ) ;
2009-08-29 18:40:52 -04:00
}
2009-11-21 17:45:39 -05:00
2010-03-03 23:00:30 -05:00
private void switchToIdentity ( Identity identity )
2009-11-24 19:40:29 -05:00
{
2009-08-29 18:40:52 -04:00
mIdentity = identity ;
mIdentityChanged = true ;
mDraftNeedsSaving = true ;
updateFrom ( ) ;
2009-11-21 17:45:39 -05:00
updateSignature ( ) ;
2009-06-08 23:11:35 -04:00
}
2009-11-21 17:45:39 -05:00
2009-11-24 19:40:29 -05:00
private void updateFrom ( )
{
if ( mIdentityChanged )
{
2009-11-21 17:45:39 -05:00
mFromView . setVisibility ( View . VISIBLE ) ;
}
mFromView . setText ( getString ( R . string . message_view_from_format , mIdentity . getName ( ) , mIdentity . getEmail ( ) ) ) ;
2009-06-08 23:11:35 -04:00
}
2009-11-21 17:45:39 -05:00
2009-11-24 19:40:29 -05:00
private void updateSignature ( )
{
2010-02-08 12:47:00 -05:00
if ( mIdentity . getSignatureUse ( ) )
{
mSignatureView . setText ( mIdentity . getSignature ( ) ) ;
mSignatureView . setVisibility ( View . VISIBLE ) ;
}
else
{
mSignatureView . setVisibility ( View . GONE ) ;
}
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -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 ;
case R . id . quoted_text_delete :
mQuotedTextBar . setVisibility ( View . GONE ) ;
mQuotedText . setVisibility ( View . GONE ) ;
2011-01-12 18:48:28 -05:00
mQuotedHTML . setVisibility ( View . GONE ) ;
2009-11-24 19:40:29 -05:00
mDraftNeedsSaving = true ;
break ;
2008-11-01 17:32:06 -04:00
}
}
2010-04-16 08:20:10 -04:00
@Override
2009-11-24 19:40:29 -05:00
public boolean onOptionsItemSelected ( MenuItem item )
{
switch ( item . getItemId ( ) )
{
case R . id . send :
2010-08-22 05:51:17 -04:00
mPgpData . setEncryptionKeys ( null ) ;
2009-11-24 19:40:29 -05:00
onSend ( ) ;
break ;
case R . id . save :
onSave ( ) ;
break ;
case R . id . discard :
onDiscard ( ) ;
break ;
case R . id . add_cc_bcc :
onAddCcBcc ( ) ;
break ;
case R . id . add_attachment :
onAddAttachment ( ) ;
break ;
2010-05-02 14:24:33 -04:00
case R . id . add_attachment_image :
onAddAttachment2 ( " image/* " ) ;
break ;
case R . id . add_attachment_video :
onAddAttachment2 ( " video/* " ) ;
break ;
2009-11-24 19:40:29 -05:00
case R . id . choose_identity :
onChooseIdentity ( ) ;
break ;
default :
return super . onOptionsItemSelected ( item ) ;
2008-11-01 17:32:06 -04:00
}
return true ;
}
2009-11-24 19:40:29 -05:00
private void onChooseIdentity ( )
{
2010-07-21 23:15:28 -04:00
// keep things simple: trigger account choice only if there are more
// than 1 account
2010-11-13 16:40:56 -05:00
if ( Preferences . getPreferences ( this ) . getAvailableAccounts ( ) . size ( ) > 1 )
2010-07-21 23:15:28 -04:00
{
final Intent intent = new Intent ( this , ChooseAccount . class ) ;
intent . putExtra ( ChooseAccount . EXTRA_ACCOUNT , mAccount . getUuid ( ) ) ;
intent . putExtra ( ChooseAccount . EXTRA_IDENTITY , mIdentity ) ;
startActivityForResult ( intent , ACTIVITY_CHOOSE_ACCOUNT ) ;
}
else if ( mAccount . getIdentities ( ) . size ( ) > 1 )
2009-11-24 19:40:29 -05:00
{
2009-11-21 17:45:39 -05:00
Intent intent = new Intent ( this , ChooseIdentity . class ) ;
2010-03-03 23:00:30 -05:00
intent . putExtra ( ChooseIdentity . EXTRA_ACCOUNT , mAccount . getUuid ( ) ) ;
2009-11-21 17:45:39 -05:00
startActivityForResult ( intent , ACTIVITY_CHOOSE_IDENTITY ) ;
2009-11-24 19:40:29 -05:00
}
else
{
2009-06-08 23:11:35 -04:00
Toast . makeText ( this , getString ( R . string . no_identities ) ,
2009-11-21 17:45:39 -05:00
Toast . LENGTH_LONG ) . show ( ) ;
2009-06-08 23:11:35 -04:00
}
}
2010-04-16 08:20:10 -04:00
@Override
2009-11-24 19:40:29 -05:00
public boolean onCreateOptionsMenu ( Menu menu )
{
2008-11-01 17:32:06 -04:00
super . onCreateOptionsMenu ( menu ) ;
getMenuInflater ( ) . inflate ( R . menu . message_compose_option , menu ) ;
2009-11-21 17:45:39 -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
* /
int found = 0 ;
for ( int i = menu . size ( ) - 1 ; i > = 0 ; i - - )
{
MenuItem item = menu . getItem ( i ) ;
int id = item . getItemId ( ) ;
if ( ( id = = R . id . add_attachment_image ) | |
2010-05-11 22:51:59 -04:00
( id = = R . id . add_attachment_video ) )
2010-05-02 14:24:33 -04:00
{
item . setVisible ( K9 . useGalleryBugWorkaround ( ) ) ;
found + + ;
}
// We found all the menu items we were looking for. So stop here.
if ( found = = 2 ) break ;
}
2008-11-01 17:32:06 -04:00
return true ;
}
2010-07-28 19:17:46 -04:00
@Override
2010-07-04 13:46:55 -04:00
public void onBackPressed ( )
{
// This will be called either automatically for you on 2.0
// or later, or by the code above on earlier versions of the
// platform.
2010-07-28 19:17:46 -04:00
if ( mDraftNeedsSaving )
{
showDialog ( DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE ) ;
}
else
{
finish ( ) ;
}
2010-07-04 13:46:55 -04:00
}
@Override
public Dialog onCreateDialog ( int id )
{
switch ( id )
{
case DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE :
return new AlertDialog . Builder ( this )
2010-07-06 06:29:26 -04:00
. 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 ( )
{
public void onClick ( DialogInterface dialog , int whichButton )
2010-07-04 13:46:55 -04:00
{
2011-01-12 18:48:28 -05:00
dismissDialog ( DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE ) ;
2010-07-06 06:29:26 -04:00
onSave ( ) ;
}
} )
. setNegativeButton ( R . string . discard_action , new DialogInterface . OnClickListener ( )
{
public void onClick ( DialogInterface dialog , int whichButton )
2010-07-04 13:46:55 -04:00
{
2011-01-12 18:48:28 -05:00
dismissDialog ( DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE ) ;
2010-07-06 06:29:26 -04:00
onDiscard ( ) ;
}
} )
. create ( ) ;
2010-07-04 13:46:55 -04:00
}
return super . onCreateDialog ( id ) ;
}
@Override
public boolean onKeyDown ( int keyCode , KeyEvent event )
{
if (
// TODO - when we move to android 2.0, uncomment this.
// android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR &&
keyCode = = KeyEvent . KEYCODE_BACK
& & event . getRepeatCount ( ) = = 0
& & K9 . manageBack ( ) )
{
// Take care of calling this method on earlier versions of
// the platform where it doesn't exist.
onBackPressed ( ) ;
return true ;
}
return super . onKeyDown ( keyCode , event ) ;
}
2008-11-01 17:32:06 -04:00
/ * *
* Returns true if all attachments were able to be attached , otherwise returns false .
* /
2009-11-24 19:40:29 -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 ;
2009-11-24 19:40:29 -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 ;
2009-11-24 19:40:29 -05:00
}
else
{
2008-11-01 17:32:06 -04:00
String contentType = MimeUtility . unfoldAndDecode ( part . getContentType ( ) ) ;
String name = MimeUtility . getHeaderParameter ( contentType , " name " ) ;
2009-11-24 19:40:29 -05:00
if ( name ! = null )
{
2008-11-01 17:32:06 -04:00
Body body = part . getBody ( ) ;
2009-11-24 19:40:29 -05:00
if ( body ! = null & & body instanceof LocalAttachmentBody )
{
2008-11-01 17:32:06 -04:00
final Uri uri = ( ( LocalAttachmentBody ) body ) . getContentUri ( ) ;
2009-11-24 19:40:29 -05:00
mHandler . post ( new Runnable ( )
{
public void run ( )
{
2008-11-01 17:32:06 -04:00
addAttachment ( uri ) ;
}
} ) ;
2009-11-24 19:40:29 -05:00
}
else
{
2008-11-01 17:32:06 -04:00
return false ;
}
}
return true ;
}
}
/ * *
* 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 .
2010-12-24 19:26:59 -05:00
* @param message Source message
2008-11-01 17:32:06 -04:00
* /
2009-11-24 19:40:29 -05:00
private void processSourceMessage ( Message message )
{
2008-11-01 17:32:06 -04:00
String action = getIntent ( ) . getAction ( ) ;
2011-01-10 15:12:08 -05:00
try
2009-11-24 19:40:29 -05:00
{
2011-01-10 15:12:08 -05:00
if ( ACTION_REPLY . equals ( action ) | | ACTION_REPLY_ALL . equals ( action ) )
2009-11-24 19:40:29 -05:00
{
2010-08-07 15:25:47 -04:00
if ( message . getSubject ( ) ! = null )
2009-11-24 19:40:29 -05:00
{
2010-08-07 15:25:47 -04:00
final String subject = prefix . matcher ( message . getSubject ( ) ) . replaceFirst ( " " ) ;
2010-08-29 19:39:26 -04:00
if ( ! subject . toLowerCase ( ) . startsWith ( " re: " ) )
2010-08-07 15:25:47 -04:00
{
mSubjectView . setText ( " Re: " + subject ) ;
}
else
{
mSubjectView . setText ( subject ) ;
}
2009-11-24 19:40:29 -05:00
}
else
{
2010-08-07 15:25:47 -04:00
mSubjectView . setText ( " " ) ;
2008-11-01 17:32:06 -04:00
}
2010-08-07 15:25:47 -04:00
2008-11-01 17:32:06 -04:00
/ *
* If a reply - to was included with the message use that , otherwise use the from
* or sender address .
* /
Address [ ] replyToAddresses ;
2009-11-24 19:40:29 -05:00
if ( message . getReplyTo ( ) . length > 0 )
{
2010-12-01 01:04:12 -05:00
replyToAddresses = message . getReplyTo ( ) ;
2009-11-24 19:40:29 -05:00
}
else
{
2010-12-01 01:32:29 -05:00
replyToAddresses = message . getFrom ( ) ;
2008-11-01 17:32:06 -04:00
}
2009-11-21 17:45:39 -05:00
2010-12-01 01:32:29 -05:00
// if we're replying to a message we sent, we probably meant
2010-12-01 01:04:12 -05:00
// to reply to the recipient of that message
2010-12-01 01:32:29 -05:00
if ( mAccount . isAnIdentity ( replyToAddresses ) )
2010-12-01 01:04:12 -05:00
{
2010-12-01 01:32:29 -05:00
replyToAddresses = message . getRecipients ( RecipientType . TO ) ;
2010-12-01 01:04:12 -05:00
}
addAddresses ( mToView , replyToAddresses ) ;
2009-11-24 19:40:29 -05:00
if ( message . getMessageId ( ) ! = null & & message . getMessageId ( ) . length ( ) > 0 )
{
2010-11-30 22:00:36 -05:00
mInReplyTo = message . getMessageId ( ) ;
2009-11-21 17:45:39 -05:00
2009-11-24 19:40:29 -05:00
if ( message . getReferences ( ) ! = null & & message . getReferences ( ) . length > 0 )
{
2009-11-21 17:45:39 -05:00
StringBuffer buffy = new StringBuffer ( ) ;
for ( int i = 0 ; i < message . getReferences ( ) . length ; i + + )
buffy . append ( message . getReferences ( ) [ i ] ) ;
mReferences = buffy . toString ( ) + " " + mInReplyTo ;
2009-11-24 19:40:29 -05:00
}
else
{
2009-11-21 17:45:39 -05:00
mReferences = mInReplyTo ;
2009-11-17 16:13:29 -05:00
}
2009-11-24 19:40:29 -05:00
}
else
{
2010-01-02 20:50:41 -05:00
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " could not get Message-ID. " ) ;
2009-11-17 16:13:29 -05:00
}
2009-11-21 17:45:39 -05:00
2011-01-12 18:48:28 -05:00
// Quote the message and setup the UI.
populateUIWithQuotedMessage ( ) ;
2009-11-21 17:45:39 -05:00
2009-11-24 19:40:29 -05:00
if ( ACTION_REPLY_ALL . equals ( action ) | | ACTION_REPLY . equals ( action ) )
{
2010-03-03 23:00:30 -05:00
Identity useIdentity = null ;
2009-11-24 19:40:29 -05:00
for ( Address address : message . getRecipients ( RecipientType . TO ) )
{
2010-03-03 23:00:30 -05:00
Identity identity = mAccount . findIdentity ( address ) ;
2009-11-24 19:40:29 -05:00
if ( identity ! = null )
{
2009-08-29 18:40:52 -04:00
useIdentity = identity ;
break ;
}
}
2009-11-24 19:40:29 -05:00
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 ) ;
2009-11-24 19:40:29 -05:00
if ( identity ! = null )
{
2009-08-29 18:40:52 -04:00
useIdentity = identity ;
break ;
2009-11-21 17:45:39 -05:00
}
2009-08-29 18:40:52 -04:00
}
}
}
2009-11-24 19:40:29 -05:00
if ( useIdentity ! = null )
{
2010-03-03 23:00:30 -05:00
Identity defaultIdentity = mAccount . getIdentity ( 0 ) ;
2009-11-24 19:40:29 -05:00
if ( useIdentity ! = defaultIdentity )
{
2009-08-29 18:40:52 -04:00
switchToIdentity ( useIdentity ) ;
}
2009-11-21 17:45:39 -05:00
}
2009-08-29 18:40:52 -04:00
}
2009-11-21 17:45:39 -05:00
2009-11-24 19:40:29 -05:00
if ( ACTION_REPLY_ALL . equals ( action ) )
{
for ( Address address : message . getRecipients ( RecipientType . TO ) )
{
if ( ! mAccount . isAnIdentity ( address ) )
{
2008-11-01 17:32:06 -04:00
addAddress ( mToView , address ) ;
}
2009-11-21 17:45:39 -05:00
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
if ( message . getRecipients ( RecipientType . CC ) . length > 0 )
{
for ( Address address : message . getRecipients ( RecipientType . CC ) )
{
if ( ! mAccount . isAnIdentity ( address ) & & ! Utility . arrayContains ( replyToAddresses , address ) )
{
2008-11-01 17:32:06 -04:00
addAddress ( mCcView , address ) ;
}
2009-11-21 17:45:39 -05:00
2008-11-01 17:32:06 -04:00
}
mCcView . setVisibility ( View . VISIBLE ) ;
}
}
2009-11-24 19:40:29 -05:00
}
2011-01-10 15:12:08 -05:00
else if ( ACTION_FORWARD . equals ( action ) )
2009-11-24 19:40:29 -05:00
{
if ( message . getSubject ( ) ! = null & & ! message . getSubject ( ) . toLowerCase ( ) . startsWith ( " fwd: " ) )
{
2008-11-01 17:32:06 -04:00
mSubjectView . setText ( " Fwd: " + message . getSubject ( ) ) ;
2009-11-24 19:40:29 -05:00
}
else
{
2008-11-01 17:32:06 -04:00
mSubjectView . setText ( message . getSubject ( ) ) ;
}
2010-10-05 02:04:16 -04:00
2011-01-12 18:48:28 -05:00
// Quote the message and setup the UI.
populateUIWithQuotedMessage ( ) ;
2010-10-05 02:04:16 -04:00
2009-11-24 19:40:29 -05:00
if ( ! mSourceMessageProcessed )
{
if ( ! loadAttachments ( message , 0 ) )
{
2008-11-01 17:32:06 -04:00
mHandler . sendEmptyMessage ( MSG_SKIPPED_ATTACHMENTS ) ;
}
}
2009-11-24 19:40:29 -05:00
}
2011-01-10 15:12:08 -05:00
else if ( ACTION_EDIT_DRAFT . equals ( action ) )
2009-11-24 19:40:29 -05:00
{
2010-03-03 23:00:30 -05:00
mDraftUid = message . getUid ( ) ;
2008-11-01 17:32:06 -04:00
mSubjectView . setText ( message . getSubject ( ) ) ;
addAddresses ( mToView , message . getRecipients ( RecipientType . TO ) ) ;
2009-11-24 19:40:29 -05:00
if ( message . getRecipients ( RecipientType . CC ) . length > 0 )
{
2008-11-01 17:32:06 -04:00
addAddresses ( mCcView , message . getRecipients ( RecipientType . CC ) ) ;
mCcView . setVisibility ( View . VISIBLE ) ;
}
2011-01-10 21:49:00 -05:00
Address [ ] bccRecipients = message . getRecipients ( RecipientType . BCC ) ;
if ( bccRecipients . length > 0 )
2009-11-24 19:40:29 -05:00
{
2011-01-10 21:49:00 -05:00
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.
mBccView . setVisibility ( View . GONE ) ;
}
else
{
mBccView . setVisibility ( View . VISIBLE ) ;
}
2008-11-01 17:32:06 -04:00
}
2009-11-21 17:45:39 -05:00
2010-06-02 12:29:59 -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 ] ;
}
// Read References header from draft
final String [ ] references = message . getHeader ( " References " ) ;
if ( ( references ! = null ) & & ( references . length > = 1 ) )
{
mReferences = references [ 0 ] ;
}
2009-11-24 19:40:29 -05:00
if ( ! mSourceMessageProcessed )
{
2009-06-08 23:11:35 -04:00
loadAttachments ( message , 0 ) ;
}
2011-01-12 18:48:28 -05: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 ] ) ;
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " Parsed identity: " + k9identity . toString ( ) ) ;
}
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 ( ) ) ;
}
if ( k9identity . containsKey ( IdentityField . NAME ) )
{
newIdentity . setName ( k9identity . get ( IdentityField . NAME ) ) ;
mIdentityChanged = true ;
}
else
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
newIdentity . setName ( mIdentity . getName ( ) ) ;
}
2009-11-21 17:45:39 -05:00
2011-01-12 18:48:28 -05:00
if ( k9identity . containsKey ( IdentityField . EMAIL ) )
{
newIdentity . setEmail ( k9identity . get ( IdentityField . EMAIL ) ) ;
mIdentityChanged = true ;
}
else
{
newIdentity . setEmail ( mIdentity . getEmail ( ) ) ;
}
mIdentity = newIdentity ;
updateSignature ( ) ;
updateFrom ( ) ;
Integer bodyLength = k9identity . get ( IdentityField . LENGTH ) ! = null
2011-01-13 20:37:52 -05:00
? Integer . parseInt ( k9identity . get ( IdentityField . LENGTH ) )
: 0 ;
2011-01-12 18:48:28 -05:00
Integer bodyOffset = k9identity . get ( IdentityField . OFFSET ) ! = null
2011-01-13 20:37:52 -05:00
? Integer . parseInt ( k9identity . get ( IdentityField . OFFSET ) )
: 0 ;
2011-01-12 18:48:28 -05: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.
if ( mAccount . getMessageFormat ( ) = = MessageFormat . HTML )
{
if ( k9identity . get ( IdentityField . MESSAGE_FORMAT ) = = null | | ! MessageFormat . valueOf ( k9identity . get ( IdentityField . MESSAGE_FORMAT ) ) . equals ( MessageFormat . HTML ) )
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
// 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.
mMessageContentView . setText ( getBodyTextFromMessage ( message , MessageFormat . TEXT ) ) ;
2011-01-13 20:37:52 -05:00
}
else
{
2011-01-12 18:48:28 -05:00
Part part = MimeUtility . findFirstPartByMimeType ( message , " text/html " ) ;
if ( part ! = null ) // Shouldn't happen if we were the one who saved it.
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
String text = MimeUtility . getTextFromPart ( part ) ;
if ( K9 . DEBUG )
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
Log . d ( K9 . LOG_TAG , " Loading message with offset " + bodyOffset + " , length " + bodyLength + " . Text length is " + text . length ( ) + " . " ) ;
2009-11-24 19:40:29 -05:00
}
2011-01-12 18:48:28 -05:00
// Grab our reply text.
String bodyText = text . substring ( bodyOffset , bodyOffset + bodyLength ) ;
mMessageContentView . setText ( HtmlConverter . htmlToText ( bodyText ) ) ;
// 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 )
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
mQuotedHtmlContent = new InsertableHtmlContent ( ) ;
mQuotedHtmlContent . setQuotedContent ( quotedHTML ) ;
mQuotedHtmlContent . setHeaderInsertionPoint ( bodyOffset ) ;
mQuotedHTML . loadDataWithBaseURL ( " http:// " , mQuotedHtmlContent . getQuotedContent ( ) , " text/html " , " utf-8 " , null ) ;
mQuotedHTML . setVisibility ( View . VISIBLE ) ;
mQuotedTextBar . setVisibility ( View . VISIBLE ) ;
2009-11-21 17:45:39 -05:00
}
}
2011-01-12 18:48:28 -05:00
}
}
else if ( mAccount . getMessageFormat ( ) = = MessageFormat . TEXT )
{
MessageFormat format = k9identity . get ( IdentityField . MESSAGE_FORMAT ) ! = null
2011-01-13 20:37:52 -05:00
? MessageFormat . valueOf ( k9identity . get ( IdentityField . MESSAGE_FORMAT ) )
: null ;
2011-01-12 18:48:28 -05:00
if ( format = = null )
{
mMessageContentView . setText ( getBodyTextFromMessage ( message , MessageFormat . TEXT ) ) ;
}
else if ( format . equals ( MessageFormat . HTML ) )
{
// We are in text mode, but have an HTML message.
Part htmlPart = MimeUtility . findFirstPartByMimeType ( message , " text/html " ) ;
if ( htmlPart ! = null ) // Shouldn't happen if we were the one who saved it.
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
String text = MimeUtility . getTextFromPart ( htmlPart ) ;
if ( K9 . DEBUG )
{
Log . d ( K9 . LOG_TAG , " Loading message with offset " + bodyOffset + " , length " + bodyLength + " . Text length is " + text . length ( ) + " . " ) ;
}
2009-11-21 17:45:39 -05:00
2011-01-12 18:48:28 -05:00
// Grab our reply text.
String bodyText = text . substring ( bodyOffset , bodyOffset + bodyLength ) ;
mMessageContentView . setText ( Html . fromHtml ( bodyText ) . toString ( ) ) ;
2009-11-21 17:45:39 -05:00
2011-01-12 18:48:28 -05:00
// Regenerate the quoted html without out content in it.
StringBuilder quotedHTML = new StringBuilder ( ) ;
quotedHTML . append ( text . substring ( 0 , bodyOffset ) ) ; // stuff before the reply
quotedHTML . append ( text . substring ( bodyOffset + bodyLength ) ) ;
// Convert it to text.
mQuotedText . setText ( HtmlConverter . htmlToText ( quotedHTML . toString ( ) ) ) ;
2009-11-21 17:45:39 -05:00
2011-01-12 18:48:28 -05:00
mQuotedTextBar . setVisibility ( View . VISIBLE ) ;
mQuotedText . setVisibility ( View . VISIBLE ) ;
2009-11-24 19:40:29 -05:00
}
else
{
2011-01-12 18:48:28 -05:00
Log . e ( K9 . LOG_TAG , " Found an HTML draft but couldn't find the HTML part! Something's wrong. " ) ;
2009-11-21 17:45:39 -05:00
}
2009-06-08 23:11:35 -04:00
}
2011-01-12 18:48:28 -05:00
else if ( format . equals ( MessageFormat . TEXT ) )
2009-11-24 19:40:29 -05:00
{
2011-01-12 18:48:28 -05:00
Part textPart = MimeUtility . findFirstPartByMimeType ( message , " text/plain " ) ;
if ( textPart ! = null )
{
String text = MimeUtility . getTextFromPart ( textPart ) ;
// 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.
if ( bodyLength ! = null & & bodyLength + 1 < text . length ( ) ) // + 1 to get rid of the newline we added when saving the draft
{
String bodyText = text . substring ( 0 , bodyLength ) ;
String quotedText = text . substring ( bodyLength + 1 , text . length ( ) ) ;
2009-06-08 23:11:35 -04:00
2011-01-12 18:48:28 -05:00
mMessageContentView . setText ( bodyText ) ;
mQuotedText . setText ( quotedText ) ;
2009-06-08 23:11:35 -04:00
2011-01-12 18:48:28 -05:00
mQuotedTextBar . setVisibility ( View . VISIBLE ) ;
mQuotedText . setVisibility ( View . VISIBLE ) ;
mQuotedHTML . setVisibility ( View . VISIBLE ) ;
}
else
{
mMessageContentView . setText ( text ) ;
}
}
2009-11-24 19:40:29 -05:00
}
else
{
2011-01-12 18:48:28 -05:00
Log . e ( K9 . LOG_TAG , " Unhandled message format. " ) ;
2009-06-08 23:11:35 -04:00
}
2008-11-01 17:32:06 -04:00
}
2009-11-24 19:40:29 -05:00
}
2011-01-10 15:12:08 -05: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 ) ;
2008-11-01 17:32:06 -04:00
}
mSourceMessageProcessed = true ;
mDraftNeedsSaving = false ;
}
2011-01-12 18:48:28 -05:00
/ * *
* Build and populate the UI with the quoted message .
* @throws MessagingException
* /
private void populateUIWithQuotedMessage ( ) throws MessagingException
{
// 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.
String content = mSourceMessageBody ! = null
2011-01-13 20:37:52 -05:00
? mSourceMessageBody
: getBodyTextFromMessage ( mSourceMessage , mAccount . getMessageFormat ( ) ) ;
2011-01-12 18:48:28 -05:00
if ( mAccount . getMessageFormat ( ) = = MessageFormat . HTML )
{
// Add the HTML reply header to the top of the content.
mQuotedHtmlContent = quoteOriginalHtmlMessage ( mSourceMessage , content , mAccount . getQuoteStyle ( ) ) ;
// Load the message with the reply header.
mQuotedHTML . loadDataWithBaseURL ( " http:// " , mQuotedHtmlContent . getQuotedContent ( ) , " text/html " , " utf-8 " , null ) ;
mQuotedTextBar . setVisibility ( View . VISIBLE ) ;
mQuotedHTML . setVisibility ( View . VISIBLE ) ;
}
else if ( mAccount . getMessageFormat ( ) = = MessageFormat . TEXT )
{
mQuotedText . setText ( quoteOriginalTextMessage ( mSourceMessage , content , mAccount . getQuoteStyle ( ) ) ) ;
mQuotedTextBar . setVisibility ( View . VISIBLE ) ;
mQuotedText . setVisibility ( View . VISIBLE ) ;
}
}
/ * *
* 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
* /
private String getBodyTextFromMessage ( final Message message , final MessageFormat format ) throws MessagingException
{
Part part ;
if ( format = = MessageFormat . HTML )
{
// HTML takes precedence, then text.
part = MimeUtility . findFirstPartByMimeType ( message , " text/html " ) ;
if ( part ! = null )
{
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " getBodyTextFromMessage: HTML requested, HTML found. " ) ;
return MimeUtility . getTextFromPart ( part ) ;
}
part = MimeUtility . findFirstPartByMimeType ( message , " text/plain " ) ;
if ( part ! = null )
{
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " getBodyTextFromMessage: HTML requested, text found. " ) ;
return HtmlConverter . textToHtml ( MimeUtility . getTextFromPart ( part ) ) ;
}
}
else if ( format = = MessageFormat . TEXT )
{
// Text takes precedence, then html.
part = MimeUtility . findFirstPartByMimeType ( message , " text/plain " ) ;
if ( part ! = null )
{
if ( K9 . DEBUG )
Log . d ( K9 . LOG_TAG , " getBodyTextFromMessage: Text requested, text found. " ) ;
return MimeUtility . getTextFromPart ( part ) ;
}
part = MimeUtility . findFirstPartByMimeType ( message , " text/html " ) ;
if ( part ! = null )
{
if ( K9 . DEBUG )
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?
private static final String FIND_INSERTION_POINT_HTML_CONTENT = " <!DOCTYPE html PUBLIC \" -//W3C//DTD HTML 4.0 Transitional//EN \" > \ n<html> " ;
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 ;
/ * *
* < 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 .
* /
private InsertableHtmlContent findInsertionPoints ( final String content )
{
InsertableHtmlContent insertable = new InsertableHtmlContent ( ) ;
// If there is no content, don't bother doing any of the regex dancing.
if ( content = = null | | content . equals ( " " ) )
{
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 ) ;
if ( htmlMatcher . matches ( ) )
{
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 ) ;
if ( headMatcher . matches ( ) )
{
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 ) ;
if ( bodyMatcher . matches ( ) )
{
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.
if ( hasBodyTag )
{
insertable . setQuotedContent ( new StringBuilder ( content ) ) ;
insertable . setHeaderInsertionPoint ( bodyMatcher . end ( FIND_INSERTION_POINT_FIRST_GROUP ) ) ;
}
else if ( hasHeadTag )
{
// 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 ) ) ;
}
else if ( hasHtmlTag )
{
// 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 ( ) ) ;
}
else
{
// 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 ( ) ) ;
if ( htmlEndMatcher . matches ( ) )
{
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 ( ) ) ;
if ( bodyEndMatcher . matches ( ) )
{
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.
if ( hasBodyEndTag )
{
insertable . setFooterInsertionPoint ( bodyEndMatcher . start ( FIND_INSERTION_POINT_FIRST_GROUP ) ) ;
}
else if ( hasHtmlEndTag )
{
// Check for an HTML tag. Add ourselves just before it.
insertable . setFooterInsertionPoint ( htmlEndMatcher . start ( FIND_INSERTION_POINT_FIRST_GROUP ) ) ;
}
else
{
// 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 ;
}
2009-11-24 19:40:29 -05:00
class Listener extends MessagingListener
{
2008-11-01 17:32:06 -04:00
@Override
2009-11-24 19:40:29 -05:00
public void loadMessageForViewStarted ( Account account , String folder , String uid )
{
2010-07-21 23:15:28 -04:00
if ( ( mMessageReference = = null ) | | ! mMessageReference . uid . equals ( uid ) )
2009-11-24 19:40:29 -05:00
{
2009-10-17 23:30:42 -04:00
return ;
}
2008-11-01 17:32:06 -04:00
mHandler . sendEmptyMessage ( MSG_PROGRESS_ON ) ;
}
@Override
2009-11-24 19:40:29 -05:00
public void loadMessageForViewFinished ( Account account , String folder , String uid , Message message )
{
2010-07-21 23:15:28 -04:00
if ( ( mMessageReference = = null ) | | ! mMessageReference . uid . equals ( uid ) )
2009-11-24 19:40:29 -05:00
{
2009-10-17 23:30:42 -04:00
return ;
}
2008-11-01 17:32:06 -04:00
mHandler . sendEmptyMessage ( MSG_PROGRESS_OFF ) ;
}
@Override
2009-11-24 19:40:29 -05:00
public void loadMessageForViewBodyAvailable ( Account account , String folder , String uid , final Message message )
{
2010-07-21 23:15:28 -04:00
if ( ( mMessageReference = = null ) | | ! mMessageReference . uid . equals ( uid ) )
2009-11-24 19:40:29 -05:00
{
2009-10-17 23:30:42 -04:00
return ;
}
2008-11-01 17:32:06 -04:00
mSourceMessage = message ;
2009-11-24 19:40:29 -05:00
runOnUiThread ( new Runnable ( )
{
public void run ( )
{
2008-11-01 17:32:06 -04:00
processSourceMessage ( message ) ;
}
} ) ;
}
@Override
2009-11-24 19:40:29 -05:00
public void loadMessageForViewFailed ( Account account , String folder , String uid , Throwable t )
{
2010-07-21 23:15:28 -04:00
if ( ( mMessageReference = = null ) | | ! mMessageReference . uid . equals ( uid ) )
2009-11-24 19:40:29 -05:00
{
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
2009-11-24 19:40:29 -05:00
public void messageUidChanged ( Account account , String folder , String oldUid , String newUid )
{
2010-07-21 23:15:28 -04:00
//TODO: is this really necessary here? mDraftUid is update after the call to MessagingController.saveDraft()
// Track UID changes of the draft message
if ( account . equals ( mAccount ) & &
2010-07-21 23:40:30 -04:00
folder . equals ( mAccount . getDraftsFolderName ( ) ) & &
oldUid . equals ( mDraftUid ) )
2009-11-24 19:40:29 -05:00
{
2010-07-21 23:15:28 -04:00
mDraftUid = newUid ;
2010-03-03 23:00:30 -05:00
}
2010-04-29 00:59:14 -04:00
2010-07-21 23:15:28 -04:00
// Track UID changes of the source message
if ( mMessageReference ! = null )
2010-03-03 23:00:30 -05:00
{
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 ;
2010-07-21 23:15:28 -04:00
if ( account . equals ( sourceAccount ) & & ( folder . equals ( sourceFolder ) ) )
2009-11-24 19:40:29 -05:00
{
2010-07-21 23:15:28 -04:00
if ( oldUid . equals ( sourceMessageUid ) )
{
mMessageReference . uid = newUid ;
}
if ( ( mSourceMessage ! = null ) & & ( oldUid . equals ( mSourceMessage . getUid ( ) ) ) )
{
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 .
* /
2010-11-13 21:27:42 -05:00
private void initializeFromMailto ( Uri mailtoUri )
2010-04-29 00:59:14 -04:00
{
2010-11-13 21:27:42 -05:00
String schemaSpecific = mailtoUri . getSchemeSpecificPart ( ) ;
int end = schemaSpecific . indexOf ( '?' ) ;
if ( end = = - 1 )
2010-01-28 01:25:10 -05:00
{
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 .
* /
Uri uri = 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 " ) ;
if ( recipient . length ( ) ! = 0 )
2010-01-28 01:25:10 -05:00
{
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
}
2010-11-13 21:27:42 -05:00
setRecipients ( mToView , to ) ;
// Read carbon copy recipients from the "cc" parameter.
boolean ccOrBcc = setRecipients ( mCcView , uri . getQueryParameters ( " cc " ) ) ;
// Read blind carbon copy recipients from the "bcc" parameter.
ccOrBcc | = setRecipients ( mBccView , uri . getQueryParameters ( " bcc " ) ) ;
2010-01-28 01:25:10 -05:00
2010-11-13 21:27:42 -05:00
if ( ccOrBcc )
2010-01-28 01:25:10 -05:00
{
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 " ) ;
if ( subject . size ( ) > 0 )
{
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 " ) ;
if ( body . size ( ) > 0 )
{
mMessageContentView . setText ( body . get ( 0 ) ) ;
}
2010-04-29 00:59:14 -04:00
}
2010-07-21 23:40:22 -04:00
private class SendMessageTask extends AsyncTask < Void , Void , Void >
{
2010-07-28 19:17:46 -04:00
@Override
2010-07-21 23:40:22 -04:00
protected Void doInBackground ( Void . . . params )
{
/ *
* Create the message from all the data the user has entered .
* /
MimeMessage message ;
try
{
2011-01-12 18:48:28 -05:00
message = createMessage ( false ) ; // isDraft = true
2010-07-21 23:40:22 -04:00
}
catch ( MessagingException me )
{
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 ) ;
}
2010-10-30 16:35:49 -04:00
try
{
final Contacts contacts = Contacts . getInstance ( MessageCompose . this ) ;
contacts . markAsContacted ( message . getRecipients ( RecipientType . TO ) ) ;
contacts . markAsContacted ( message . getRecipients ( RecipientType . CC ) ) ;
contacts . markAsContacted ( message . getRecipients ( RecipientType . BCC ) ) ;
}
catch ( Exception e )
{
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 ) ;
if ( mDraftUid ! = null )
{
MessagingController . getInstance ( getApplication ( ) ) . deleteDraft ( mAccount , mDraftUid ) ;
mDraftUid = null ;
}
return null ;
}
}
private class SaveMessageTask extends AsyncTask < Void , Void , Void >
{
2010-07-28 19:17:46 -04:00
@Override
2010-07-21 23:40:22 -04:00
protected Void doInBackground ( Void . . . params )
{
/ *
* Create the message from all the data the user has entered .
* /
MimeMessage message ;
try
{
2011-01-12 18:48:28 -05:00
message = createMessage ( true ) ; // isDraft = true
2010-07-21 23:40:22 -04:00
}
catch ( MessagingException me )
{
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
* /
if ( mDraftUid ! = null )
{
message . setUid ( mDraftUid ) ;
}
else if ( ACTION_EDIT_DRAFT . equals ( getIntent ( ) . getAction ( ) ) )
{
/ *
* We ' re saving a previously saved draft , so update the new message ' s uid
* to the old message ' s uid .
* /
2010-10-23 11:26:50 -04:00
if ( mMessageReference ! = null )
{
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 ( ) ) ;
Message draftMessage = messagingController . saveDraft ( mAccount , message ) ;
2010-07-21 23:40:22 -04:00
mDraftUid = draftMessage . getUid ( ) ;
// Don't display the toast if the user is just changing the orientation
if ( ( getChangingConfigurations ( ) & ActivityInfo . CONFIG_ORIENTATION ) = = 0 )
{
mHandler . sendEmptyMessage ( MSG_SAVED_DRAFT ) ;
}
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-01-12 18:48:28 -05:00
private String quoteOriginalTextMessage ( final Message originalMessage , final String messageBody , final QuoteStyle quoteStyle ) throws MessagingException
2011-01-05 18:58:14 -05:00
{
2011-01-05 20:31:28 -05:00
String body = messageBody = = null ? " " : messageBody ;
2011-01-12 18:48:28 -05:00
if ( quoteStyle = = QuoteStyle . PREFIX )
2011-01-05 18:58:14 -05:00
{
StringBuilder quotedText = new StringBuilder ( body . length ( ) + QUOTE_BUFFER_LENGTH ) ;
quotedText . append ( String . format (
2011-01-13 20:37:52 -05:00
getString ( R . string . message_compose_reply_header_fmt ) ,
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-01-12 18:48:28 -05:00
else if ( quoteStyle = = QuoteStyle . HEADER )
2011-01-05 18:58:14 -05:00
{
StringBuilder quotedText = new StringBuilder ( body . length ( ) + QUOTE_BUFFER_LENGTH ) ;
quotedText . append ( " \ n " ) ;
quotedText . append ( getString ( R . string . message_compose_quote_header_separator ) ) . append ( " \ n " ) ;
if ( originalMessage . getFrom ( ) ! = null & & Address . toString ( originalMessage . getFrom ( ) ) . length ( ) ! = 0 )
{
quotedText . append ( getString ( R . string . message_compose_quote_header_from ) ) . append ( " " ) . append ( Address . toString ( originalMessage . getFrom ( ) ) ) . append ( " \ n " ) ;
}
if ( originalMessage . getSentDate ( ) ! = null )
{
quotedText . append ( getString ( R . string . message_compose_quote_header_send_date ) ) . append ( " " ) . append ( originalMessage . getSentDate ( ) ) . append ( " \ n " ) ;
}
if ( originalMessage . getRecipients ( RecipientType . TO ) ! = null & & originalMessage . getRecipients ( RecipientType . TO ) . length ! = 0 )
{
quotedText . append ( getString ( R . string . message_compose_quote_header_to ) ) . append ( " " ) . append ( Address . toString ( originalMessage . getRecipients ( RecipientType . TO ) ) ) . append ( " \ n " ) ;
}
if ( originalMessage . getRecipients ( RecipientType . CC ) ! = null & & originalMessage . getRecipients ( RecipientType . CC ) . length ! = 0 )
{
2011-01-05 20:34:08 -05:00
quotedText . append ( getString ( R . string . message_compose_quote_header_cc ) ) . append ( " " ) . append ( Address . toString ( originalMessage . getRecipients ( RecipientType . CC ) ) ) . append ( " \ n " ) ;
2011-01-05 18:58:14 -05:00
}
if ( originalMessage . getSubject ( ) ! = null )
{
quotedText . append ( getString ( R . string . message_compose_quote_header_subject ) ) . append ( " " ) . append ( originalMessage . getSubject ( ) ) . append ( " \ n " ) ;
}
quotedText . append ( " \ n " ) ;
2011-01-05 20:31:28 -05:00
quotedText . append ( body ) ;
2011-01-05 18:58:14 -05:00
return quotedText . toString ( ) ;
}
else
{
// 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
* /
private InsertableHtmlContent quoteOriginalHtmlMessage ( final Message originalMessage , final String messageBody , final QuoteStyle quoteStyle ) throws MessagingException
{
InsertableHtmlContent insertable = findInsertionPoints ( messageBody ) ;
if ( quoteStyle = = QuoteStyle . PREFIX )
{
StringBuilder header = new StringBuilder ( QUOTE_BUFFER_LENGTH ) ;
header . append ( " <br><div class= \" gmail_quote \" > " ) ;
// Remove all trailing newlines so that the quote starts immediately after the header. "Be like Gmail!"
header . append ( HtmlConverter . textToHtmlFragment ( String . format (
2011-01-13 20:37:52 -05:00
getString ( R . string . message_compose_reply_header_fmt ) . replaceAll ( " \ n$ " , " " ) ,
Address . toString ( originalMessage . getFrom ( ) ) )
) ) ;
2011-01-12 18:48:28 -05:00
header . append ( " <blockquote class= \" gmail_quote \" " +
2011-01-13 20:37:52 -05:00
" style= \" margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex; \" > \ n " ) ;
2011-01-12 18:48:28 -05:00
String footer = " </blockquote></div> " ;
insertable . insertIntoQuotedHeader ( header . toString ( ) ) ;
insertable . insertIntoQuotedFooter ( footer ) ;
}
else if ( quoteStyle = = QuoteStyle . HEADER )
{
StringBuilder header = new StringBuilder ( ) ;
header . append ( " <div style='font-size:10.0pt;font-family: \" Tahoma \" , \" sans-serif \" ;padding:3.0pt 0in 0in 0in'> \ n " ) ;
header . append ( " <hr style='border:none;border-top:solid #B5C4DF 1.0pt'> \ n " ) ; // This gets converted into a horizontal line during html to text conversion.
if ( mSourceMessage . getFrom ( ) ! = null & & Address . toString ( mSourceMessage . getFrom ( ) ) . length ( ) ! = 0 )
{
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_from ) ) . append ( " </b> " ) . append ( HtmlConverter . textToHtmlFragment ( Address . toString ( mSourceMessage . getFrom ( ) ) ) ) . append ( " <br> \ n " ) ;
}
if ( mSourceMessage . getSentDate ( ) ! = null )
{
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_send_date ) ) . append ( " </b> " ) . append ( mSourceMessage . getSentDate ( ) ) . append ( " <br> \ n " ) ;
}
if ( mSourceMessage . getRecipients ( RecipientType . TO ) ! = null & & mSourceMessage . getRecipients ( RecipientType . TO ) . length ! = 0 )
{
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_to ) ) . append ( " </b> " ) . append ( HtmlConverter . textToHtmlFragment ( Address . toString ( mSourceMessage . getRecipients ( RecipientType . TO ) ) ) ) . append ( " <br> \ n " ) ;
}
if ( mSourceMessage . getRecipients ( RecipientType . CC ) ! = null & & mSourceMessage . getRecipients ( RecipientType . CC ) . length ! = 0 )
{
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_cc ) ) . append ( " </b> " ) . append ( HtmlConverter . textToHtmlFragment ( Address . toString ( mSourceMessage . getRecipients ( RecipientType . CC ) ) ) ) . append ( " <br> \ n " ) ;
}
if ( mSourceMessage . getSubject ( ) ! = null )
{
header . append ( " <b> " ) . append ( getString ( R . string . message_compose_quote_header_subject ) ) . append ( " </b> " ) . append ( HtmlConverter . textToHtmlFragment ( mSourceMessage . getSubject ( ) ) ) . append ( " <br> \ n " ) ;
}
header . append ( " </div> \ n " ) ;
header . append ( " <br> \ n " ) ;
insertable . insertIntoQuotedHeader ( header . toString ( ) ) ;
}
return insertable ;
}
2008-11-01 17:32:06 -04:00
}