use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class MessagingController method saveDraft.
/**
* Save a draft message.
*
* @param account
* Account we are saving for.
* @param message
* Message to save.
*
* @return Message representing the entry in the local store.
*/
public Message saveDraft(final Account account, final Message message, long existingDraftId, boolean saveRemotely) {
Message localMessage = null;
try {
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(account.getDraftsFolderName());
localFolder.open(Folder.OPEN_MODE_RW);
if (existingDraftId != INVALID_MESSAGE_ID) {
String uid = localFolder.getMessageUidById(existingDraftId);
message.setUid(uid);
}
// Save the message to the store.
localFolder.appendMessages(Collections.singletonList(message));
// Fetch the message back from the store. This is the Message that's returned to the caller.
localMessage = localFolder.getMessage(message.getUid());
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
if (saveRemotely) {
PendingCommand command = PendingAppend.create(localFolder.getName(), localMessage.getUid());
queuePendingCommand(account, command);
processPendingCommands(account);
}
} catch (MessagingException e) {
Timber.e(e, "Unable to save message as draft.");
addErrorMessage(account, null, e);
}
return localMessage;
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class MessagingController method updateMoreMessages.
private void updateMoreMessages(Folder remoteFolder, LocalFolder localFolder, Date earliestDate, int remoteStart) throws MessagingException, IOException {
if (remoteStart == 1) {
localFolder.setMoreMessages(MoreMessages.FALSE);
} else {
boolean moreMessagesAvailable = remoteFolder.areMoreMessagesAvailable(remoteStart, earliestDate);
MoreMessages newMoreMessages = (moreMessagesAvailable) ? MoreMessages.TRUE : MoreMessages.FALSE;
localFolder.setMoreMessages(newMoreMessages);
}
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class MessagingController method downloadPartial.
private void downloadPartial(Folder remoteFolder, LocalFolder localFolder, Message message) throws MessagingException {
/*
* We have a structure to deal with, from which
* we can pull down the parts we want to actually store.
* Build a list of parts we are interested in. Text parts will be downloaded
* right now, attachments will be left for later.
*/
Set<Part> viewables = MessageExtractor.collectTextParts(message);
/*
* Now download the parts we're interested in storing.
*/
for (Part part : viewables) {
remoteFolder.fetchPart(message, part, null);
}
// Store the updated message locally
localFolder.appendMessages(Collections.singletonList(message));
Message localMessage = localFolder.getMessage(message.getUid());
// Set a flag indicating this message has been fully downloaded and can be
// viewed.
localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class FolderSettings method saveSettings.
private void saveSettings() throws MessagingException {
mFolder.setInTopGroup(mInTopGroup.isChecked());
mFolder.setIntegrate(mIntegrate.isChecked());
// We call getPushClass() because display class changes can affect push class when push class is set to inherit
FolderClass oldPushClass = mFolder.getPushClass();
FolderClass oldDisplayClass = mFolder.getDisplayClass();
mFolder.setDisplayClass(FolderClass.valueOf(mDisplayClass.getValue()));
mFolder.setSyncClass(FolderClass.valueOf(mSyncClass.getValue()));
mFolder.setPushClass(FolderClass.valueOf(mPushClass.getValue()));
mFolder.setNotifyClass(FolderClass.valueOf(mNotifyClass.getValue()));
mFolder.save();
FolderClass newPushClass = mFolder.getPushClass();
FolderClass newDisplayClass = mFolder.getDisplayClass();
if (oldPushClass != newPushClass || (newPushClass != FolderClass.NO_CLASS && oldDisplayClass != newDisplayClass)) {
MailService.actionRestartPushers(getApplication(), null);
}
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class FolderSettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String folderName = (String) getIntent().getSerializableExtra(EXTRA_FOLDER_NAME);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
try {
LocalStore localStore = mAccount.getLocalStore();
mFolder = localStore.getFolder(folderName);
mFolder.open(Folder.OPEN_MODE_RW);
} catch (MessagingException me) {
Timber.e(me, "Unable to edit folder %s preferences", folderName);
return;
}
boolean isPushCapable = false;
try {
Store store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
} catch (Exception e) {
Timber.e(e, "Could not get remote store");
}
addPreferencesFromResource(R.xml.folder_settings_preferences);
String displayName = FolderInfoHolder.getDisplayName(this, mAccount, mFolder.getName());
Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
category.setTitle(displayName);
mInTopGroup = (CheckBoxPreference) findPreference(PREFERENCE_IN_TOP_GROUP);
mInTopGroup.setChecked(mFolder.isInTopGroup());
mIntegrate = (CheckBoxPreference) findPreference(PREFERENCE_INTEGRATE);
mIntegrate.setChecked(mFolder.isIntegrate());
mDisplayClass = (ListPreference) findPreference(PREFERENCE_DISPLAY_CLASS);
mDisplayClass.setValue(mFolder.getDisplayClass().name());
mDisplayClass.setSummary(mDisplayClass.getEntry());
mDisplayClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mDisplayClass.findIndexOfValue(summary);
mDisplayClass.setSummary(mDisplayClass.getEntries()[index]);
mDisplayClass.setValue(summary);
return false;
}
});
mSyncClass = (ListPreference) findPreference(PREFERENCE_SYNC_CLASS);
mSyncClass.setValue(mFolder.getRawSyncClass().name());
mSyncClass.setSummary(mSyncClass.getEntry());
mSyncClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mSyncClass.findIndexOfValue(summary);
mSyncClass.setSummary(mSyncClass.getEntries()[index]);
mSyncClass.setValue(summary);
return false;
}
});
mPushClass = (ListPreference) findPreference(PREFERENCE_PUSH_CLASS);
mPushClass.setEnabled(isPushCapable);
mPushClass.setValue(mFolder.getRawPushClass().name());
mPushClass.setSummary(mPushClass.getEntry());
mPushClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mPushClass.findIndexOfValue(summary);
mPushClass.setSummary(mPushClass.getEntries()[index]);
mPushClass.setValue(summary);
return false;
}
});
mNotifyClass = (ListPreference) findPreference(PREFERENCE_NOTIFY_CLASS);
mNotifyClass.setValue(mFolder.getRawNotifyClass().name());
mNotifyClass.setSummary(mNotifyClass.getEntry());
mNotifyClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mNotifyClass.findIndexOfValue(summary);
mNotifyClass.setSummary(mNotifyClass.getEntries()[index]);
mNotifyClass.setValue(summary);
return false;
}
});
}
Aggregations