This commit is contained in:
danapple 2011-03-02 07:34:54 -06:00
parent 107408c0d9
commit 32b5afc702
10 changed files with 83 additions and 115 deletions

View File

@ -66,7 +66,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
private SearchAccount unreadAccount = null;
private SearchAccount integratedInboxAccount = null;
private FontSizes mFontSizes = K9.getFontSizes();
private static final int ACTIVITY_REQUEST_PICK_SETTINGS_FILE = 1;
class AccountsHandler extends Handler {
@ -138,12 +138,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
});
}
}
public void setProgress(boolean progress)
{
public void setProgress(boolean progress) {
mHandler.progress(progress);
}
ActivityListener mListener = new ActivityListener() {
@Override
public void informUserOfStatus() {
@ -240,15 +239,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
intent.putExtra(EXTRA_STARTUP, false);
context.startActivity(intent);
}
@Override
public void onNewIntent(Intent intent)
{
public void onNewIntent(Intent intent) {
Uri uri = intent.getData();
Log.i(K9.LOG_TAG, "Accounts Activity got uri " + uri);
if (uri != null) {
ContentResolver contentResolver = getContentResolver();
Log.i(K9.LOG_TAG, "Accounts Activity got content of type " + contentResolver.getType(uri));
String contentType = contentResolver.getType(uri);
@ -273,7 +271,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
Account[] accounts = Preferences.getPreferences(this).getAccounts();
Intent intent = getIntent();
boolean startup = intent.getData() == null && intent.getBooleanExtra(EXTRA_STARTUP, true);
onNewIntent(intent);
onNewIntent(intent);
if (startup && K9.startIntegratedInbox()) {
onOpenAccount(integratedInboxAccount);
finish();
@ -299,7 +297,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
restoreAccountStats(icicle);
}
}
@SuppressWarnings("unchecked")
@ -782,76 +780,61 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
}
}
private void onImport()
{
private void onImport() {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i, null), ACTIVITY_REQUEST_PICK_SETTINGS_FILE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(K9.LOG_TAG, "onActivityResult requestCode = " + requestCode + ", resultCode = " + resultCode + ", data = " + data);
if (resultCode != RESULT_OK)
return;
if (data == null)
{
if (data == null) {
return;
}
switch (requestCode)
{
case ACTIVITY_REQUEST_PICK_SETTINGS_FILE:
onImport(data.getData());
break;
switch (requestCode) {
case ACTIVITY_REQUEST_PICK_SETTINGS_FILE:
onImport(data.getData());
break;
}
}
private void onImport(Uri uri)
{
private void onImport(Uri uri) {
Log.i(K9.LOG_TAG, "onImport importing from URI " + uri.getPath());
try
{
try {
final String fileName = uri.getPath();
ContentResolver resolver = getContentResolver();
final InputStream is = resolver.openInputStream(uri);
PasswordEntryDialog dialog = new PasswordEntryDialog(this, getString(R.string.settings_encryption_password_prompt),
new PasswordEntryDialog.PasswordEntryListener()
{
public void passwordChosen(String chosenPassword)
{
String toastText = Accounts.this.getString(R.string.settings_importing );
PasswordEntryDialog dialog = new PasswordEntryDialog(this, getString(R.string.settings_encryption_password_prompt),
new PasswordEntryDialog.PasswordEntryListener() {
public void passwordChosen(String chosenPassword) {
String toastText = Accounts.this.getString(R.string.settings_importing);
Toast toast = Toast.makeText(Accounts.this.getApplication(), toastText, Toast.LENGTH_SHORT);
toast.show();
mHandler.progress(true);
AsyncUIProcessor.getInstance(Accounts.this.getApplication()).importSettings(is, chosenPassword, new ImportListener()
{
public void failure(final String message, Exception e)
{
Accounts.this.runOnUiThread(new Runnable()
{
public void run()
{
AsyncUIProcessor.getInstance(Accounts.this.getApplication()).importSettings(is, chosenPassword, new ImportListener() {
public void failure(final String message, Exception e) {
Accounts.this.runOnUiThread(new Runnable() {
public void run() {
mHandler.progress(false);
showDialog(Accounts.this, R.string.settings_import_failed_header, Accounts.this.getString(R.string.settings_import_failure, fileName, message));
}
});
}
public void importSuccess(final int numAccounts)
{
Accounts.this.runOnUiThread(new Runnable()
{
public void run()
{
public void importSuccess(final int numAccounts) {
Accounts.this.runOnUiThread(new Runnable() {
public void run() {
mHandler.progress(false);
String messageText =
numAccounts != 1
? Accounts.this.getString(R.string.settings_import_success_multiple, numAccounts, fileName )
: Accounts.this.getString(R.string.settings_import_success_single, fileName );
String messageText =
numAccounts != 1
? Accounts.this.getString(R.string.settings_import_success_multiple, numAccounts, fileName)
: Accounts.this.getString(R.string.settings_import_success_single, fileName);
showDialog(Accounts.this, R.string.settings_import_success_header, messageText);
refresh();
}
@ -859,23 +842,19 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
});
}
public void cancel()
{
public void cancel() {
}
});
dialog.show();
}
catch (FileNotFoundException fnfe)
{
String toastText = Accounts.this.getString(R.string.settings_import_failure, uri.getPath(), fnfe.getMessage() );
} catch (FileNotFoundException fnfe) {
String toastText = Accounts.this.getString(R.string.settings_import_failure, uri.getPath(), fnfe.getMessage());
Toast toast = Toast.makeText(Accounts.this.getApplication(), toastText, 1);
toast.show();
}
}
private static void showDialog(final Activity activity, int headerRes, String message)
{
private static void showDialog(final Activity activity, int headerRes, String message) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(headerRes);
builder.setMessage(message);
@ -886,7 +865,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
dialog.dismiss();
}
});
builder.show();
}

View File

@ -37,8 +37,7 @@ public class ActivityListener extends MessagingListener {
String displayName = mLoadingFolderName;
if (K9.INBOX.equalsIgnoreCase(displayName)) {
displayName = context.getString(R.string.special_mailbox_name_inbox);
}
else if ((mAccount != null) && mAccount.getOutboxFolderName().equals(displayName)) {
} else if ((mAccount != null) && mAccount.getOutboxFolderName().equals(displayName)) {
displayName = context.getString(R.string.special_mailbox_name_outbox);
}

View File

@ -48,8 +48,7 @@ public class ExportHelper {
});
dialog.show();
}
private static void showDialog(final Activity activity, int headerRes, String message)
{
private static void showDialog(final Activity activity, int headerRes, String message) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(headerRes);
builder.setMessage(message);
@ -60,7 +59,7 @@ public class ExportHelper {
dialog.dismiss();
}
});
builder.show();
}
}

View File

@ -150,12 +150,11 @@ public class FolderList extends K9ListActivity {
});
}
}
public void setProgress(boolean progress)
{
public void setProgress(boolean progress) {
mHandler.progress(progress);
}
/**
* This class is responsible for reloading the list of local messages for a
* given folder, notifying the adapter that the message have been loaded and
@ -543,15 +542,15 @@ public class FolderList extends K9ListActivity {
onCompact(mAccount);
return true;
case R.id.export:
onExport(mAccount);
return true;
case R.id.export_all:
onExport(null);
return true;
case R.id.display_1st_class: {
setDisplayMode(FolderMode.FIRST_CLASS);
return true;

View File

@ -518,12 +518,11 @@ public class MessageList
});
}
}
public void setProgress(boolean progress)
{
public void setProgress(boolean progress) {
mHandler.progress(progress);
}
public static void actionHandleFolder(Context context, Account account, String folder) {
Intent intent = actionHandleFolderIntent(context, account, folder);
context.startActivity(intent);
@ -1405,7 +1404,7 @@ public class MessageList
case R.id.export: {
onExport(mAccount);
return true;
}
}
case R.id.export_all: {
onExport(null);
return true;

View File

@ -943,13 +943,13 @@ public class MessageView extends K9Activity implements OnClickListener {
@Override
protected Dialog onCreateDialog(final int id) {
switch (id) {
case R.id.dialog_confirm_delete:
return createConfirmDeleteDialog(id);
case R.id.dialog_attachment_progress:
ProgressDialog d = new ProgressDialog(this);
d.setIndeterminate(true);
d.setTitle(R.string.dialog_attachment_progress_title);
return d;
case R.id.dialog_confirm_delete:
return createConfirmDeleteDialog(id);
case R.id.dialog_attachment_progress:
ProgressDialog d = new ProgressDialog(this);
d.setIndeterminate(true);
d.setTitle(R.string.dialog_attachment_progress_title);
return d;
}
return super.onCreateDialog(id);
}

View File

@ -853,12 +853,10 @@ public class AccountSettings extends K9PreferenceActivity {
// TODO: In the future the call above should be changed to only return remote folders.
// For now we just remove the Outbox folder if present.
Iterator<? extends Folder> iter = folders.iterator();
while (iter.hasNext())
{
Iterator <? extends Folder > iter = folders.iterator();
while (iter.hasNext()) {
Folder folder = iter.next();
if (mAccount.getOutboxFolderName().equals(folder.getName()))
{
if (mAccount.getOutboxFolderName().equals(folder.getName())) {
iter.remove();
}
}

View File

@ -87,7 +87,7 @@ public class EncoderUtil {
int encodedLength = bEncodedLength(bytes);
int totalLength = prefix.length() + encodedLength
+ ENC_WORD_SUFFIX.length();
+ ENC_WORD_SUFFIX.length();
if (totalLength <= ENCODED_WORD_MAX_LENGTH) {
return prefix + org.apache.james.mime4j.codec.EncoderUtil.encodeB(bytes) + ENC_WORD_SUFFIX;
} else {
@ -111,7 +111,7 @@ public class EncoderUtil {
int encodedLength = qEncodedLength(bytes);
int totalLength = prefix.length() + encodedLength
+ ENC_WORD_SUFFIX.length();
+ ENC_WORD_SUFFIX.length();
if (totalLength <= ENCODED_WORD_MAX_LENGTH) {
return prefix + org.apache.james.mime4j.codec.EncoderUtil.encodeQ(bytes, org.apache.james.mime4j.codec.EncoderUtil.Usage.WORD_ENTITY) + ENC_WORD_SUFFIX;
} else {

View File

@ -142,8 +142,7 @@ public class MimeHeader {
}
}
public void setCharset(String charset)
{
public void setCharset(String charset) {
mCharset = charset;
}
}

View File

@ -14,25 +14,22 @@ import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
public class K9Krypto
{
public class K9Krypto {
final Base64 mBase64;
final Cipher mCipher;
private final static String AES = "AES";
private final static String SECURE_RANDOM_TYPE = "SHA1PRNG";
public enum MODE
{
public enum MODE {
ENCRYPT(Cipher.ENCRYPT_MODE), DECRYPT(Cipher.DECRYPT_MODE);
int mode;
private MODE(int nMode)
{
private MODE(int nMode) {
mode = nMode;
}
}
public K9Krypto(String key, MODE mode) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException {
mBase64 = new Base64();
KeyGenerator keyGenerator = KeyGenerator.getInstance(AES);
@ -43,25 +40,24 @@ public class K9Krypto
byte[] processedKey = secretKey.getEncoded();
mCipher = setupCipher(mode.mode, processedKey);
}
public String encrypt(String plainText) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
byte[] encryptedText = mCipher.doFinal(plainText.getBytes());
byte[] encryptedEncodedText = mBase64.encode(encryptedText);
return new String(encryptedEncodedText);
}
public String decrypt(String encryptedEncodedText) throws IllegalBlockSizeException, BadPaddingException {
byte[] encryptedText = mBase64.decode(encryptedEncodedText.getBytes());
byte[] plainText = mCipher.doFinal(encryptedText);
return new String(plainText);
}
private Cipher setupCipher(int mode, byte[] processedKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException
{
private Cipher setupCipher(int mode, byte[] processedKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
SecretKeySpec secretKeySpec = new SecretKeySpec(processedKey, AES);
Cipher cipher = Cipher.getInstance(AES);
cipher.init(mode, secretKeySpec);
return cipher;
}
}