use of com.fsck.k9.Preferences in project k-9 by k9mail.
the class MessageProviderTest method createAccount.
private void createAccount() {
Preferences preferences = Preferences.getPreferences(getMockContext());
Account account = preferences.newAccount();
account.setDescription("TestAccount");
account.setChipColor(10);
account.setStoreUri("imap://user@domain.com/");
account.save(preferences);
}
use of com.fsck.k9.Preferences in project k-9 by k9mail.
the class Account method delete.
protected synchronized void delete(Preferences preferences) {
deleteCertificates();
// Get the list of account UUIDs
String[] uuids = preferences.getStorage().getString("accountUuids", "").split(",");
// Create a list of all account UUIDs excluding this account
List<String> newUuids = new ArrayList<>(uuids.length);
for (String uuid : uuids) {
if (!uuid.equals(mUuid)) {
newUuids.add(uuid);
}
}
StorageEditor editor = preferences.getStorage().edit();
// Only change the 'accountUuids' value if this account's UUID was listed before
if (newUuids.size() < uuids.length) {
String accountUuids = Utility.combine(newUuids.toArray(), ',');
editor.putString("accountUuids", accountUuids);
}
editor.remove(mUuid + ".storeUri");
editor.remove(mUuid + ".transportUri");
editor.remove(mUuid + ".description");
editor.remove(mUuid + ".name");
editor.remove(mUuid + ".email");
editor.remove(mUuid + ".alwaysBcc");
editor.remove(mUuid + ".automaticCheckIntervalMinutes");
editor.remove(mUuid + ".pushPollOnConnect");
editor.remove(mUuid + ".idleRefreshMinutes");
editor.remove(mUuid + ".lastAutomaticCheckTime");
editor.remove(mUuid + ".latestOldMessageSeenTime");
editor.remove(mUuid + ".notifyNewMail");
editor.remove(mUuid + ".notifySelfNewMail");
editor.remove(mUuid + ".deletePolicy");
editor.remove(mUuid + ".draftsFolderName");
editor.remove(mUuid + ".sentFolderName");
editor.remove(mUuid + ".trashFolderName");
editor.remove(mUuid + ".archiveFolderName");
editor.remove(mUuid + ".spamFolderName");
editor.remove(mUuid + ".autoExpandFolderName");
editor.remove(mUuid + ".accountNumber");
editor.remove(mUuid + ".vibrate");
editor.remove(mUuid + ".vibratePattern");
editor.remove(mUuid + ".vibrateTimes");
editor.remove(mUuid + ".ring");
editor.remove(mUuid + ".ringtone");
editor.remove(mUuid + ".folderDisplayMode");
editor.remove(mUuid + ".folderSyncMode");
editor.remove(mUuid + ".folderPushMode");
editor.remove(mUuid + ".folderTargetMode");
editor.remove(mUuid + ".signatureBeforeQuotedText");
editor.remove(mUuid + ".expungePolicy");
editor.remove(mUuid + ".syncRemoteDeletions");
editor.remove(mUuid + ".maxPushFolders");
editor.remove(mUuid + ".searchableFolders");
editor.remove(mUuid + ".chipColor");
editor.remove(mUuid + ".led");
editor.remove(mUuid + ".ledColor");
editor.remove(mUuid + ".goToUnreadMessageSearch");
editor.remove(mUuid + ".subscribedFoldersOnly");
editor.remove(mUuid + ".maximumPolledMessageAge");
editor.remove(mUuid + ".maximumAutoDownloadMessageSize");
editor.remove(mUuid + ".messageFormatAuto");
editor.remove(mUuid + ".quoteStyle");
editor.remove(mUuid + ".quotePrefix");
editor.remove(mUuid + ".sortTypeEnum");
editor.remove(mUuid + ".sortAscending");
editor.remove(mUuid + ".showPicturesEnum");
editor.remove(mUuid + ".replyAfterQuote");
editor.remove(mUuid + ".stripSignature");
// this is no longer set, but cleans up legacy values
editor.remove(mUuid + ".cryptoApp");
editor.remove(mUuid + ".cryptoAutoSignature");
editor.remove(mUuid + ".cryptoAutoEncrypt");
editor.remove(mUuid + ".cryptoApp");
editor.remove(mUuid + ".cryptoKey");
editor.remove(mUuid + ".cryptoSupportSignOnly");
editor.remove(mUuid + ".enabled");
editor.remove(mUuid + ".markMessageAsReadOnView");
editor.remove(mUuid + ".alwaysShowCcBcc");
editor.remove(mUuid + ".allowRemoteSearch");
editor.remove(mUuid + ".remoteSearchFullText");
editor.remove(mUuid + ".remoteSearchNumResults");
editor.remove(mUuid + ".defaultQuotedTextShown");
editor.remove(mUuid + ".displayCount");
editor.remove(mUuid + ".inboxFolderName");
editor.remove(mUuid + ".localStorageProvider");
editor.remove(mUuid + ".messageFormat");
editor.remove(mUuid + ".messageReadReceipt");
editor.remove(mUuid + ".notifyMailCheck");
for (NetworkType type : NetworkType.values()) {
editor.remove(mUuid + ".useCompression." + type.name());
}
deleteIdentities(preferences.getStorage(), editor);
// TODO: Remove preference settings that may exist for individual
// folders in the account.
editor.commit();
}
use of com.fsck.k9.Preferences in project k-9 by k9mail.
the class Account method save.
public synchronized void save(Preferences preferences) {
StorageEditor editor = preferences.getStorage().edit();
if (!preferences.getStorage().getString("accountUuids", "").contains(mUuid)) {
/*
* When the account is first created we assign it a unique account number. The
* account number will be unique to that account for the lifetime of the account.
* So, we get all the existing account numbers, sort them ascending, loop through
* the list and check if the number is greater than 1 + the previous number. If so
* we use the previous number + 1 as the account number. This refills gaps.
* mAccountNumber starts as -1 on a newly created account. It must be -1 for this
* algorithm to work.
*
* I bet there is a much smarter way to do this. Anyone like to suggest it?
*/
List<Account> accounts = preferences.getAccounts();
int[] accountNumbers = new int[accounts.size()];
for (int i = 0; i < accounts.size(); i++) {
accountNumbers[i] = accounts.get(i).getAccountNumber();
}
Arrays.sort(accountNumbers);
for (int accountNumber : accountNumbers) {
if (accountNumber > mAccountNumber + 1) {
break;
}
mAccountNumber = accountNumber;
}
mAccountNumber++;
String accountUuids = preferences.getStorage().getString("accountUuids", "");
accountUuids += (accountUuids.length() != 0 ? "," : "") + mUuid;
editor.putString("accountUuids", accountUuids);
}
editor.putString(mUuid + ".storeUri", Base64.encode(mStoreUri));
editor.putString(mUuid + ".localStorageProvider", mLocalStorageProviderId);
editor.putString(mUuid + ".transportUri", Base64.encode(mTransportUri));
editor.putString(mUuid + ".description", mDescription);
editor.putString(mUuid + ".alwaysBcc", mAlwaysBcc);
editor.putInt(mUuid + ".automaticCheckIntervalMinutes", mAutomaticCheckIntervalMinutes);
editor.putInt(mUuid + ".idleRefreshMinutes", mIdleRefreshMinutes);
editor.putBoolean(mUuid + ".pushPollOnConnect", mPushPollOnConnect);
editor.putInt(mUuid + ".displayCount", mDisplayCount);
editor.putLong(mUuid + ".latestOldMessageSeenTime", mLatestOldMessageSeenTime);
editor.putBoolean(mUuid + ".notifyNewMail", mNotifyNewMail);
editor.putString(mUuid + ".folderNotifyNewMailMode", mFolderNotifyNewMailMode.name());
editor.putBoolean(mUuid + ".notifySelfNewMail", mNotifySelfNewMail);
editor.putBoolean(mUuid + ".notifyContactsMailOnly", mNotifyContactsMailOnly);
editor.putBoolean(mUuid + ".notifyMailCheck", mNotifySync);
editor.putInt(mUuid + ".deletePolicy", mDeletePolicy.setting);
editor.putString(mUuid + ".inboxFolderName", mInboxFolderName);
editor.putString(mUuid + ".draftsFolderName", mDraftsFolderName);
editor.putString(mUuid + ".sentFolderName", mSentFolderName);
editor.putString(mUuid + ".trashFolderName", mTrashFolderName);
editor.putString(mUuid + ".archiveFolderName", mArchiveFolderName);
editor.putString(mUuid + ".spamFolderName", mSpamFolderName);
editor.putString(mUuid + ".autoExpandFolderName", mAutoExpandFolderName);
editor.putInt(mUuid + ".accountNumber", mAccountNumber);
editor.putString(mUuid + ".sortTypeEnum", mSortType.name());
editor.putBoolean(mUuid + ".sortAscending", mSortAscending.get(mSortType));
editor.putString(mUuid + ".showPicturesEnum", mShowPictures.name());
editor.putString(mUuid + ".folderDisplayMode", mFolderDisplayMode.name());
editor.putString(mUuid + ".folderSyncMode", mFolderSyncMode.name());
editor.putString(mUuid + ".folderPushMode", mFolderPushMode.name());
editor.putString(mUuid + ".folderTargetMode", mFolderTargetMode.name());
editor.putBoolean(mUuid + ".signatureBeforeQuotedText", this.mIsSignatureBeforeQuotedText);
editor.putString(mUuid + ".expungePolicy", mExpungePolicy.name());
editor.putBoolean(mUuid + ".syncRemoteDeletions", mSyncRemoteDeletions);
editor.putInt(mUuid + ".maxPushFolders", mMaxPushFolders);
editor.putString(mUuid + ".searchableFolders", searchableFolders.name());
editor.putInt(mUuid + ".chipColor", mChipColor);
editor.putBoolean(mUuid + ".goToUnreadMessageSearch", goToUnreadMessageSearch);
editor.putBoolean(mUuid + ".subscribedFoldersOnly", subscribedFoldersOnly);
editor.putInt(mUuid + ".maximumPolledMessageAge", maximumPolledMessageAge);
editor.putInt(mUuid + ".maximumAutoDownloadMessageSize", maximumAutoDownloadMessageSize);
if (MessageFormat.AUTO.equals(mMessageFormat)) {
// saving MessageFormat.AUTO as is to the database will cause downgrades to crash on
// startup, so we save as MessageFormat.TEXT instead with a separate flag for auto.
editor.putString(mUuid + ".messageFormat", Account.MessageFormat.TEXT.name());
mMessageFormatAuto = true;
} else {
editor.putString(mUuid + ".messageFormat", mMessageFormat.name());
mMessageFormatAuto = false;
}
editor.putBoolean(mUuid + ".messageFormatAuto", mMessageFormatAuto);
editor.putBoolean(mUuid + ".messageReadReceipt", mMessageReadReceipt);
editor.putString(mUuid + ".quoteStyle", mQuoteStyle.name());
editor.putString(mUuid + ".quotePrefix", mQuotePrefix);
editor.putBoolean(mUuid + ".defaultQuotedTextShown", mDefaultQuotedTextShown);
editor.putBoolean(mUuid + ".replyAfterQuote", mReplyAfterQuote);
editor.putBoolean(mUuid + ".stripSignature", mStripSignature);
editor.putLong(mUuid + ".cryptoKey", mCryptoKey);
editor.putBoolean(mUuid + ".allowRemoteSearch", mAllowRemoteSearch);
editor.putBoolean(mUuid + ".remoteSearchFullText", mRemoteSearchFullText);
editor.putInt(mUuid + ".remoteSearchNumResults", mRemoteSearchNumResults);
editor.putBoolean(mUuid + ".enabled", mEnabled);
editor.putBoolean(mUuid + ".markMessageAsReadOnView", mMarkMessageAsReadOnView);
editor.putBoolean(mUuid + ".alwaysShowCcBcc", mAlwaysShowCcBcc);
editor.putBoolean(mUuid + ".vibrate", mNotificationSetting.shouldVibrate());
editor.putInt(mUuid + ".vibratePattern", mNotificationSetting.getVibratePattern());
editor.putInt(mUuid + ".vibrateTimes", mNotificationSetting.getVibrateTimes());
editor.putBoolean(mUuid + ".ring", mNotificationSetting.shouldRing());
editor.putString(mUuid + ".ringtone", mNotificationSetting.getRingtone());
editor.putBoolean(mUuid + ".led", mNotificationSetting.isLed());
editor.putInt(mUuid + ".ledColor", mNotificationSetting.getLedColor());
for (NetworkType type : NetworkType.values()) {
Boolean useCompression = compressionMap.get(type);
if (useCompression != null) {
editor.putBoolean(mUuid + ".useCompression." + type, useCompression);
}
}
saveIdentities(preferences.getStorage(), editor);
editor.commit();
}
use of com.fsck.k9.Preferences in project k-9 by k9mail.
the class K9 method loadPrefs.
/**
* Load preferences into our statics.
*
* If you're adding a preference here, odds are you'll need to add it to
* {@link com.fsck.k9.preferences.GlobalSettings}, too.
*
* @param prefs Preferences to load
*/
public static void loadPrefs(Preferences prefs) {
Storage storage = prefs.getStorage();
setDebug(storage.getBoolean("enableDebugLogging", BuildConfig.DEVELOPER_MODE));
DEBUG_SENSITIVE = storage.getBoolean("enableSensitiveLogging", false);
mAnimations = storage.getBoolean("animations", true);
mGesturesEnabled = storage.getBoolean("gesturesEnabled", false);
mUseVolumeKeysForNavigation = storage.getBoolean("useVolumeKeysForNavigation", false);
mUseVolumeKeysForListNavigation = storage.getBoolean("useVolumeKeysForListNavigation", false);
mStartIntegratedInbox = storage.getBoolean("startIntegratedInbox", false);
mMeasureAccounts = storage.getBoolean("measureAccounts", true);
mCountSearchMessages = storage.getBoolean("countSearchMessages", true);
mHideSpecialAccounts = storage.getBoolean("hideSpecialAccounts", false);
mMessageListSenderAboveSubject = storage.getBoolean("messageListSenderAboveSubject", false);
mMessageListCheckboxes = storage.getBoolean("messageListCheckboxes", false);
mMessageListStars = storage.getBoolean("messageListStars", true);
mMessageListPreviewLines = storage.getInt("messageListPreviewLines", 2);
mAutofitWidth = storage.getBoolean("autofitWidth", true);
mQuietTimeEnabled = storage.getBoolean("quietTimeEnabled", false);
mNotificationDuringQuietTimeEnabled = storage.getBoolean("notificationDuringQuietTimeEnabled", true);
mQuietTimeStarts = storage.getString("quietTimeStarts", "21:00");
mQuietTimeEnds = storage.getString("quietTimeEnds", "7:00");
mShowCorrespondentNames = storage.getBoolean("showCorrespondentNames", true);
mShowContactName = storage.getBoolean("showContactName", false);
sShowContactPicture = storage.getBoolean("showContactPicture", true);
mChangeContactNameColor = storage.getBoolean("changeRegisteredNameColor", false);
mContactNameColor = storage.getInt("registeredNameColor", 0xff00008f);
mMessageViewFixedWidthFont = storage.getBoolean("messageViewFixedWidthFont", false);
mMessageViewReturnToList = storage.getBoolean("messageViewReturnToList", false);
mMessageViewShowNext = storage.getBoolean("messageViewShowNext", false);
mWrapFolderNames = storage.getBoolean("wrapFolderNames", false);
mHideUserAgent = storage.getBoolean("hideUserAgent", false);
mHideTimeZone = storage.getBoolean("hideTimeZone", false);
sOpenPgpProvider = storage.getString("openPgpProvider", NO_OPENPGP_PROVIDER);
sOpenPgpSupportSignOnly = storage.getBoolean("openPgpSupportSignOnly", false);
mConfirmDelete = storage.getBoolean("confirmDelete", false);
mConfirmDiscardMessage = storage.getBoolean("confirmDiscardMessage", true);
mConfirmDeleteStarred = storage.getBoolean("confirmDeleteStarred", false);
mConfirmSpam = storage.getBoolean("confirmSpam", false);
mConfirmDeleteFromNotification = storage.getBoolean("confirmDeleteFromNotification", true);
mConfirmMarkAllRead = storage.getBoolean("confirmMarkAllRead", true);
try {
String value = storage.getString("sortTypeEnum", Account.DEFAULT_SORT_TYPE.name());
mSortType = SortType.valueOf(value);
} catch (Exception e) {
mSortType = Account.DEFAULT_SORT_TYPE;
}
boolean sortAscending = storage.getBoolean("sortAscending", Account.DEFAULT_SORT_ASCENDING);
mSortAscending.put(mSortType, sortAscending);
String notificationHideSubject = storage.getString("notificationHideSubject", null);
if (notificationHideSubject == null) {
// If the "notificationHideSubject" setting couldn't be found, the app was probably
// updated. Look for the old "keyguardPrivacy" setting and map it to the new enum.
sNotificationHideSubject = (storage.getBoolean("keyguardPrivacy", false)) ? NotificationHideSubject.WHEN_LOCKED : NotificationHideSubject.NEVER;
} else {
sNotificationHideSubject = NotificationHideSubject.valueOf(notificationHideSubject);
}
String notificationQuickDelete = storage.getString("notificationQuickDelete", null);
if (notificationQuickDelete != null) {
sNotificationQuickDelete = NotificationQuickDelete.valueOf(notificationQuickDelete);
}
String lockScreenNotificationVisibility = storage.getString("lockScreenNotificationVisibility", null);
if (lockScreenNotificationVisibility != null) {
sLockScreenNotificationVisibility = LockScreenNotificationVisibility.valueOf(lockScreenNotificationVisibility);
}
String splitViewMode = storage.getString("splitViewMode", null);
if (splitViewMode != null) {
sSplitViewMode = SplitViewMode.valueOf(splitViewMode);
}
mAttachmentDefaultPath = storage.getString("attachmentdefaultpath", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString());
sUseBackgroundAsUnreadIndicator = storage.getBoolean("useBackgroundAsUnreadIndicator", true);
sThreadedViewEnabled = storage.getBoolean("threadedView", true);
fontSizes.load(storage);
try {
setBackgroundOps(BACKGROUND_OPS.valueOf(storage.getString("backgroundOperations", BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC.name())));
} catch (Exception e) {
setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC);
}
sColorizeMissingContactPictures = storage.getBoolean("colorizeMissingContactPictures", true);
sMessageViewArchiveActionVisible = storage.getBoolean("messageViewArchiveActionVisible", false);
sMessageViewDeleteActionVisible = storage.getBoolean("messageViewDeleteActionVisible", true);
sMessageViewMoveActionVisible = storage.getBoolean("messageViewMoveActionVisible", false);
sMessageViewCopyActionVisible = storage.getBoolean("messageViewCopyActionVisible", false);
sMessageViewSpamActionVisible = storage.getBoolean("messageViewSpamActionVisible", false);
sPgpInlineDialogCounter = storage.getInt("pgpInlineDialogCounter", 0);
sPgpSignOnlyDialogCounter = storage.getInt("pgpSignOnlyDialogCounter", 0);
int themeValue = storage.getInt("theme", Theme.LIGHT.ordinal());
// necessary.
if (themeValue == Theme.DARK.ordinal() || themeValue == android.R.style.Theme) {
K9.setK9Theme(Theme.DARK);
} else {
K9.setK9Theme(Theme.LIGHT);
}
themeValue = storage.getInt("messageViewTheme", Theme.USE_GLOBAL.ordinal());
K9.setK9MessageViewThemeSetting(Theme.values()[themeValue]);
themeValue = storage.getInt("messageComposeTheme", Theme.USE_GLOBAL.ordinal());
K9.setK9ComposerThemeSetting(Theme.values()[themeValue]);
K9.setUseFixedMessageViewTheme(storage.getBoolean("fixedMessageViewTheme", true));
}
use of com.fsck.k9.Preferences in project k-9 by k9mail.
the class K9 method onCreate.
@Override
public void onCreate() {
if (K9.DEVELOPER_MODE) {
StrictMode.enableDefaults();
}
PRNGFixes.apply();
super.onCreate();
app = this;
Globals.setContext(this);
K9MailLib.setDebugStatus(new K9MailLib.DebugStatus() {
@Override
public boolean enabled() {
return DEBUG;
}
@Override
public boolean debugSensitive() {
return DEBUG_SENSITIVE;
}
});
checkCachedDatabaseVersion();
Preferences prefs = Preferences.getPreferences(this);
loadPrefs(prefs);
/*
* We have to give MimeMessage a temp directory because File.createTempFile(String, String)
* doesn't work in Android and MimeMessage does not have access to a Context.
*/
BinaryTempFileBody.setTempDirectory(getCacheDir());
LocalKeyStore.setKeyStoreLocation(getDir("KeyStore", MODE_PRIVATE).toString());
/*
* Enable background sync of messages
*/
setServicesEnabled(this);
registerReceivers();
MessagingController.getInstance(this).addListener(new SimpleMessagingListener() {
private void broadcastIntent(String action, Account account, String folder, Message message) {
Uri uri = Uri.parse("email://messages/" + account.getAccountNumber() + "/" + Uri.encode(folder) + "/" + Uri.encode(message.getUid()));
Intent intent = new Intent(action, uri);
intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folder);
intent.putExtra(K9.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate());
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FROM, Address.toString(message.getFrom()));
intent.putExtra(K9.Intents.EmailReceived.EXTRA_TO, Address.toString(message.getRecipients(Message.RecipientType.TO)));
intent.putExtra(K9.Intents.EmailReceived.EXTRA_CC, Address.toString(message.getRecipients(Message.RecipientType.CC)));
intent.putExtra(K9.Intents.EmailReceived.EXTRA_BCC, Address.toString(message.getRecipients(Message.RecipientType.BCC)));
intent.putExtra(K9.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject());
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FROM_SELF, account.isAnIdentity(message.getFrom()));
K9.this.sendBroadcast(intent);
Timber.d("Broadcasted: action=%s account=%s folder=%s message uid=%s", action, account.getDescription(), folder, message.getUid());
}
private void updateUnreadWidget() {
try {
UnreadWidgetProvider.updateUnreadCount(K9.this);
} catch (Exception e) {
Timber.e(e, "Error while updating unread widget(s)");
}
}
private void updateMailListWidget() {
try {
MessageListWidgetProvider.triggerMessageListWidgetUpdate(K9.this);
} catch (RuntimeException e) {
if (BuildConfig.DEBUG) {
throw e;
} else {
Timber.e(e, "Error while updating message list widget");
}
}
}
@Override
public void synchronizeMailboxRemovedMessage(Account account, String folder, Message message) {
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
updateUnreadWidget();
updateMailListWidget();
}
@Override
public void messageDeleted(Account account, String folder, Message message) {
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
updateUnreadWidget();
updateMailListWidget();
}
@Override
public void synchronizeMailboxNewMessage(Account account, String folder, Message message) {
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message);
updateUnreadWidget();
updateMailListWidget();
}
@Override
public void folderStatusChanged(Account account, String folderName, int unreadMessageCount) {
updateUnreadWidget();
updateMailListWidget();
// let observers know a change occurred
Intent intent = new Intent(K9.Intents.EmailReceived.ACTION_REFRESH_OBSERVER, null);
intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folderName);
K9.this.sendBroadcast(intent);
}
});
notifyObservers();
}
Aggregations