ashleywillis/k-9 — comment on commit 57b9321a1efc59a71722f980704063f17ac77df5
File:  line 0
By ashleywillis:

"What steps will reproduce the problem?
1. Reply to email by typing until see draft in Gmail web interface (using IMAP folders)
2. Then hit save as draft on device
3. Now there is 2 drafts, if message is sent only one draft is deleted"

* hitting save as draft set `mDraftNeedsSaving` to true first, therefore two exact messages could be saved.
disabled that, so `mDraftNeedsSaving` is whatever it should be.
if text was changed after auto-save, then `mDraftNeedsSaving` would be true and so two different messages saved.

"Another consideration here is if you want to send encrypted email, k9 leaves unencrypted copies on the server. It needs a way to disable the drafts functionality entirely."

* resolved as long as you don't intentionally save a draft, as this fix never auto-saves a draft.
if you do save a draft, then it still will be pushed to your server

"Setting the Drafts folder to not sync in any form (set all folder options to 'None') fixes this issue (for me, anyway), so it is likely related to this."

* does not fix for me, and it seems the code automatically pushes changes to
the draft folder and sent folder (and another one) no matter the settings.

* removed check for orientation change because it no longer applies.
* removed `saveIfNeeded()` from `onPause()` and `onSaveInstanceState(Bundle outState)`.
* added code for save/restore of `mDraftNeedsSaving` instead of setting it to false on restore.

if the following code is added then it will save if activity is changed (home screen, call received),
but this will result in unencrypted emails saved and pushed to the server:

@Override
public void onStop() {
super.onStop();
if ((getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) {
saveIfNeeded();
finish();
}
}