use of com.fsck.k9.K9 in project k-9 by k9mail.
the class Accounts method onCreateDialog.
@Override
public Dialog onCreateDialog(int id) {
// dismissed. Make sure we have all information necessary before creating a new dialog.
switch(id) {
case DIALOG_REMOVE_ACCOUNT:
{
if (mSelectedContextAccount == null) {
return null;
}
return ConfirmationDialog.create(this, id, R.string.account_delete_dlg_title, getString(R.string.account_delete_dlg_instructions_fmt, mSelectedContextAccount.getDescription()), R.string.okay_action, R.string.cancel_action, new Runnable() {
@Override
public void run() {
if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account) mSelectedContextAccount;
try {
realAccount.getLocalStore().delete();
} catch (Exception e) {
// Ignore, this may lead to localStores on sd-cards that
// are currently not inserted to be left
}
MessagingController.getInstance(getApplication()).deleteAccount(realAccount);
Preferences.getPreferences(Accounts.this).deleteAccount(realAccount);
K9.setServicesEnabled(Accounts.this);
refresh();
}
}
});
}
case DIALOG_CLEAR_ACCOUNT:
{
if (mSelectedContextAccount == null) {
return null;
}
return ConfirmationDialog.create(this, id, R.string.account_clear_dlg_title, getString(R.string.account_clear_dlg_instructions_fmt, mSelectedContextAccount.getDescription()), R.string.okay_action, R.string.cancel_action, new Runnable() {
@Override
public void run() {
if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account) mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.clearing_account);
MessagingController.getInstance(getApplication()).clear(realAccount, null);
}
}
});
}
case DIALOG_RECREATE_ACCOUNT:
{
if (mSelectedContextAccount == null) {
return null;
}
return ConfirmationDialog.create(this, id, R.string.account_recreate_dlg_title, getString(R.string.account_recreate_dlg_instructions_fmt, mSelectedContextAccount.getDescription()), R.string.okay_action, R.string.cancel_action, new Runnable() {
@Override
public void run() {
if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account) mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.recreating_account);
MessagingController.getInstance(getApplication()).recreate(realAccount, null);
}
}
});
}
case DIALOG_NO_FILE_MANAGER:
{
return ConfirmationDialog.create(this, id, R.string.import_dialog_error_title, getString(R.string.import_dialog_error_message), R.string.open_market, R.string.close, new Runnable() {
@Override
public void run() {
Uri uri = Uri.parse(ANDROID_MARKET_URL);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
}
}
return super.onCreateDialog(id);
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class FolderList method checkMail.
/**
* 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
* queueing up a remote update of the folder.
*/
private void checkMail(FolderInfoHolder folder) {
TracingPowerManager pm = TracingPowerManager.getPowerManager(this);
final TracingWakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "FolderList checkMail");
wakeLock.setReferenceCounted(false);
wakeLock.acquire(K9.WAKE_LOCK_TIMEOUT);
MessagingListener listener = new SimpleMessagingListener() {
@Override
public void synchronizeMailboxFinished(Account account, String folder, int totalMessagesInMailbox, int numNewMessages) {
if (!account.equals(mAccount)) {
return;
}
wakeLock.release();
}
@Override
public void synchronizeMailboxFailed(Account account, String folder, String message) {
if (!account.equals(mAccount)) {
return;
}
wakeLock.release();
}
};
MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, folder.name, listener, null);
sendMail(mAccount);
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class MessageCryptoPresenter method maybeHandleShowMessage.
public boolean maybeHandleShowMessage(MessageTopView messageView, Account account, MessageViewInfo messageViewInfo) {
this.cryptoResultAnnotation = messageViewInfo.cryptoResultAnnotation;
MessageCryptoDisplayStatus displayStatus = MessageCryptoDisplayStatus.fromResultAnnotation(messageViewInfo.cryptoResultAnnotation);
if (displayStatus == MessageCryptoDisplayStatus.DISABLED) {
return false;
}
boolean suppressSignOnlyMessages = !K9.getOpenPgpSupportSignOnly();
if (suppressSignOnlyMessages && displayStatus.isUnencryptedSigned()) {
return false;
}
messageView.getMessageHeaderView().setCryptoStatus(displayStatus);
switch(displayStatus) {
case UNENCRYPTED_SIGN_REVOKED:
case ENCRYPTED_SIGN_REVOKED:
{
showMessageCryptoWarning(messageView, account, messageViewInfo, R.string.messageview_crypto_warning_revoked);
break;
}
case UNENCRYPTED_SIGN_EXPIRED:
case ENCRYPTED_SIGN_EXPIRED:
{
showMessageCryptoWarning(messageView, account, messageViewInfo, R.string.messageview_crypto_warning_expired);
break;
}
case UNENCRYPTED_SIGN_INSECURE:
case ENCRYPTED_SIGN_INSECURE:
{
showMessageCryptoWarning(messageView, account, messageViewInfo, R.string.messageview_crypto_warning_insecure);
break;
}
case UNENCRYPTED_SIGN_ERROR:
case ENCRYPTED_SIGN_ERROR:
{
showMessageCryptoWarning(messageView, account, messageViewInfo, R.string.messageview_crypto_warning_error);
break;
}
case ENCRYPTED_UNSIGNED:
{
showMessageCryptoWarning(messageView, account, messageViewInfo, R.string.messageview_crypto_warning_unsigned);
break;
}
case CANCELLED:
{
Drawable providerIcon = getOpenPgpApiProviderIcon(messageView.getContext());
messageView.showMessageCryptoCancelledView(messageViewInfo, providerIcon);
break;
}
case INCOMPLETE_ENCRYPTED:
{
Drawable providerIcon = getOpenPgpApiProviderIcon(messageView.getContext());
messageView.showMessageEncryptedButIncomplete(messageViewInfo, providerIcon);
break;
}
case ENCRYPTED_ERROR:
case UNSUPPORTED_ENCRYPTED:
{
Drawable providerIcon = getOpenPgpApiProviderIcon(messageView.getContext());
messageView.showMessageCryptoErrorView(messageViewInfo, providerIcon);
break;
}
case ENCRYPTED_NO_PROVIDER:
{
messageView.showCryptoProviderNotConfigured(messageViewInfo);
break;
}
case INCOMPLETE_SIGNED:
case UNSUPPORTED_SIGNED:
default:
{
messageView.showMessage(account, messageViewInfo);
break;
}
case LOADING:
{
throw new IllegalStateException("Displaying message while in loading state!");
}
}
return true;
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class MessageListFragment method onResume.
/**
* On resume we refresh messages for the folder that is currently open.
* This guarantees that things like unread message count and read status
* are updated.
*/
@Override
public void onResume() {
super.onResume();
senderAboveSubject = K9.messageListSenderAboveSubject();
if (!loaderJustInitialized) {
restartLoader();
} else {
loaderJustInitialized = false;
}
// Check if we have connectivity. Cache the value.
if (hasConnectivity == null) {
hasConnectivity = Utility.hasConnectivity(getActivity().getApplication());
}
localBroadcastManager.registerReceiver(cacheBroadcastReceiver, cacheIntentFilter);
activityListener.onResume(getActivity());
messagingController.addListener(activityListener);
//Cancel pending new mail notifications when we open an account
List<Account> accountsWithNotification;
Account account = this.account;
if (account != null) {
accountsWithNotification = Collections.singletonList(account);
} else {
accountsWithNotification = preferences.getAccounts();
}
for (Account accountWithNotification : accountsWithNotification) {
messagingController.cancelNotificationsForAccount(accountWithNotification);
}
if (this.account != null && folderName != null && !search.isManualSearch()) {
messagingController.getFolderUnreadMessageCount(this.account, folderName, activityListener);
}
updateTitle();
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class MessagingController method loadMessageRemoteSynchronous.
private boolean loadMessageRemoteSynchronous(final Account account, final String folder, final String uid, final MessagingListener listener, final boolean loadPartialFromSearch) {
Folder remoteFolder = null;
LocalFolder localFolder = null;
try {
LocalStore localStore = account.getLocalStore();
localFolder = localStore.getFolder(folder);
localFolder.open(Folder.OPEN_MODE_RW);
LocalMessage message = localFolder.getMessage(uid);
if (uid.startsWith(K9.LOCAL_UID_PREFIX)) {
Timber.w("Message has local UID so cannot download fully.");
// ASH move toast
android.widget.Toast.makeText(context, "Message has local UID so cannot download fully", android.widget.Toast.LENGTH_LONG).show();
// TODO: Using X_DOWNLOADED_FULL is wrong because it's only a partial message. But
// one we can't download completely. Maybe add a new flag; X_PARTIAL_MESSAGE ?
message.setFlag(Flag.X_DOWNLOADED_FULL, true);
message.setFlag(Flag.X_DOWNLOADED_PARTIAL, false);
}
/* commented out because this was pulled from another unmerged branch:
} else if (localFolder.isLocalOnly() && !force) {
Log.w(K9.LOG_TAG, "Message in local-only folder so cannot download fully.");
// ASH move toast
android.widget.Toast.makeText(mApplication,
"Message in local-only folder so cannot download fully",
android.widget.Toast.LENGTH_LONG).show();
message.setFlag(Flag.X_DOWNLOADED_FULL, true);
message.setFlag(Flag.X_DOWNLOADED_PARTIAL, false);
}*/
/*if (!message.isSet(Flag.X_DOWNLOADED_FULL)) */
{
/*
* At this point the message is not available, so we need to download it
* fully if possible.
*/
Store remoteStore = account.getRemoteStore();
remoteFolder = remoteStore.getFolder(folder);
remoteFolder.open(Folder.OPEN_MODE_RW);
// Get the remote message and fully download it
Message remoteMessage = remoteFolder.getMessage(uid);
if (loadPartialFromSearch) {
downloadMessages(account, remoteFolder, localFolder, Collections.singletonList(remoteMessage), false, false);
} else {
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.BODY);
remoteFolder.fetch(Collections.singletonList(remoteMessage), fp, null);
localFolder.appendMessages(Collections.singletonList(remoteMessage));
}
message = localFolder.getMessage(uid);
if (!loadPartialFromSearch) {
message.setFlag(Flag.X_DOWNLOADED_FULL, true);
}
}
// Mark that this message is now fully synched
if (account.isMarkMessageAsReadOnView()) {
message.setFlag(Flag.SEEN, true);
}
// now that we have the full message, refresh the headers
for (MessagingListener l : getListeners(listener)) {
l.loadMessageRemoteFinished(account, folder, uid);
}
return true;
} catch (Exception e) {
for (MessagingListener l : getListeners(listener)) {
l.loadMessageRemoteFailed(account, folder, uid, e);
}
notifyUserIfCertificateProblem(account, e, true);
addErrorMessage(account, null, e);
return false;
} finally {
closeFolder(remoteFolder);
closeFolder(localFolder);
}
}
Aggregations