diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index 0fdab7d86..8de469b09 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -659,7 +659,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC onRecreate(realAccount); break; case R.id.export: - onExport(realAccount); + onExport(false, realAccount); break; } return true; @@ -708,7 +708,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC onSearchRequested(); break; case R.id.export_all: - onExport(null); + onExport(true, null); break; case R.id.import_settings: onImport(); @@ -1110,7 +1110,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC } - public void onExport(final Account account) { + public void onExport(final boolean includeGlobals, final Account account) { // TODO, prompt to allow a user to choose which accounts to export HashSet accountUuids; @@ -1119,7 +1119,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC accountUuids.add(account.getUuid()); } - ExportHelper.exportSettings(this, accountUuids, new ExportListener() { + ExportHelper.exportSettings(this, includeGlobals, accountUuids, new ExportListener() { @Override public void canceled() { diff --git a/src/com/fsck/k9/activity/AsyncUIProcessor.java b/src/com/fsck/k9/activity/AsyncUIProcessor.java index 264e49dbc..0ab2971e7 100644 --- a/src/com/fsck/k9/activity/AsyncUIProcessor.java +++ b/src/com/fsck/k9/activity/AsyncUIProcessor.java @@ -42,7 +42,7 @@ public class AsyncUIProcessor { public void execute(Runnable runnable) { threadPool.execute(runnable); } - public void exportSettings(final Activity activity, final String storageFormat, final Set accountUuids, final ExportListener listener) { + public void exportSettings(final Activity activity, final String storageFormat, final boolean includeGlobals, final Set accountUuids, final ExportListener listener) { threadPool.execute(new Runnable() { @Override @@ -55,7 +55,7 @@ public class AsyncUIProcessor { dir.mkdirs(); File file = Utility.createUniqueFile(dir, "settings.k9s"); String fileName = file.getAbsolutePath(); - StorageExporter.exportPreferences(activity, storageFormat, accountUuids, fileName, null, listener); + StorageExporter.exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, listener); } catch (Exception e) { Log.w(K9.LOG_TAG, "Exception during export", e); listener.failure(e.getLocalizedMessage(), e); diff --git a/src/com/fsck/k9/activity/ExportHelper.java b/src/com/fsck/k9/activity/ExportHelper.java index 1fd1fa575..6ab57932b 100644 --- a/src/com/fsck/k9/activity/ExportHelper.java +++ b/src/com/fsck/k9/activity/ExportHelper.java @@ -12,10 +12,10 @@ import com.fsck.k9.R; import com.fsck.k9.preferences.StorageFormat; public class ExportHelper { - public static void exportSettings(final Activity activity, final Set accountUuids, final ExportListener listener) { + public static void exportSettings(final Activity activity, final boolean includeGlobals, final Set accountUuids, final ExportListener listener) { // Once there are more file formats, build a UI to select which one to use. For now, use the encrypted/encoded format: String storageFormat = StorageFormat.ENCRYPTED_XML_FILE; - AsyncUIProcessor.getInstance(activity.getApplication()).exportSettings(activity, storageFormat, accountUuids, new ExportListener() { + AsyncUIProcessor.getInstance(activity.getApplication()).exportSettings(activity, storageFormat, includeGlobals, accountUuids, new ExportListener() { @Override public void canceled() { diff --git a/src/com/fsck/k9/preferences/IStorageExporter.java b/src/com/fsck/k9/preferences/IStorageExporter.java index 63cbd00f6..095db3f36 100644 --- a/src/com/fsck/k9/preferences/IStorageExporter.java +++ b/src/com/fsck/k9/preferences/IStorageExporter.java @@ -8,5 +8,5 @@ import android.content.Context; public interface IStorageExporter { public boolean needsKey(); - public void exportPreferences(Context context, Set accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException; + public void exportPreferences(Context context, boolean includeGlobals, Set accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException; } diff --git a/src/com/fsck/k9/preferences/StorageExporter.java b/src/com/fsck/k9/preferences/StorageExporter.java index 148d09c3b..890d2b2b4 100644 --- a/src/com/fsck/k9/preferences/StorageExporter.java +++ b/src/com/fsck/k9/preferences/StorageExporter.java @@ -16,16 +16,16 @@ import com.fsck.k9.activity.ExportListener; import com.fsck.k9.activity.PasswordEntryDialog; public class StorageExporter { - private static void exportPreferences(Activity activity, String storageFormat, Set accountUuids, String fileName, OutputStream os, String encryptionKey, final ExportListener listener) { + private static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set accountUuids, String fileName, OutputStream os, String encryptionKey, final ExportListener listener) { try { IStorageExporter storageExporter = StorageFormat.createExporter(storageFormat); if (storageExporter == null) { throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat), null); } if (storageExporter.needsKey() && encryptionKey == null) { - gatherPassword(activity, storageExporter, accountUuids, fileName, os, listener); + gatherPassword(activity, storageExporter, includeGlobals, accountUuids, fileName, os, listener); } else { - finishExport(activity, storageExporter, accountUuids, fileName, os, encryptionKey, listener); + finishExport(activity, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey, listener); } } @@ -36,15 +36,15 @@ public class StorageExporter { } } - public static void exportPreferences(Activity activity, String storageFormat, Set accountUuids, String fileName, String encryptionKey, final ExportListener listener) throws StorageImportExportException { - exportPreferences(activity, storageFormat, accountUuids, fileName, null, encryptionKey, listener); + public static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set accountUuids, String fileName, String encryptionKey, final ExportListener listener) throws StorageImportExportException { + exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, encryptionKey, listener); } - public static void exportPrefererences(Activity activity, String storageFormat, HashSet accountUuids, OutputStream os, String encryptionKey, final ExportListener listener) throws StorageImportExportException { - exportPreferences(activity, storageFormat, accountUuids, null, os, encryptionKey, listener); + public static void exportPrefererences(Activity activity, String storageFormat, boolean includeGlobals, HashSet accountUuids, OutputStream os, String encryptionKey, final ExportListener listener) throws StorageImportExportException { + exportPreferences(activity, storageFormat, includeGlobals, accountUuids, null, os, encryptionKey, listener); } - private static void gatherPassword(final Activity activity, final IStorageExporter storageExporter, final Set accountUuids, final String fileName, final OutputStream os, final ExportListener listener) { + private static void gatherPassword(final Activity activity, final IStorageExporter storageExporter, final boolean includeGlobals, final Set accountUuids, final String fileName, final OutputStream os, final ExportListener listener) { activity.runOnUiThread(new Runnable() { @Override @@ -58,7 +58,7 @@ public class StorageExporter { @Override public void run() { try { - finishExport(activity, storageExporter, accountUuids, fileName, os, chosenPassword, listener); + finishExport(activity, storageExporter, includeGlobals, accountUuids, fileName, os, chosenPassword, listener); } catch (Exception e) { Log.w(K9.LOG_TAG, "Exception while finishing export", e); if (listener != null) { @@ -82,7 +82,7 @@ public class StorageExporter { } - private static void finishExport(Activity activity, IStorageExporter storageExporter, Set accountUuids, String fileName, OutputStream os, String encryptionKey, ExportListener listener) throws StorageImportExportException { + private static void finishExport(Activity activity, IStorageExporter storageExporter, boolean includeGlobals, Set accountUuids, String fileName, OutputStream os, String encryptionKey, ExportListener listener) throws StorageImportExportException { boolean needToClose = false; if (listener != null) { listener.started(); @@ -96,7 +96,7 @@ public class StorageExporter { os = new FileOutputStream(outFile); } if (os != null) { - storageExporter.exportPreferences(activity, accountUuids, os, encryptionKey); + storageExporter.exportPreferences(activity, includeGlobals, accountUuids, os, encryptionKey); if (listener != null) { if (fileName != null) { listener.success(fileName); diff --git a/src/com/fsck/k9/preferences/StorageExporterEncryptedXml.java b/src/com/fsck/k9/preferences/StorageExporterEncryptedXml.java index eb2ec1e6d..b406834fa 100644 --- a/src/com/fsck/k9/preferences/StorageExporterEncryptedXml.java +++ b/src/com/fsck/k9/preferences/StorageExporterEncryptedXml.java @@ -16,7 +16,7 @@ import com.fsck.k9.K9; import com.fsck.k9.Preferences; public class StorageExporterEncryptedXml implements IStorageExporter { - public void exportPreferences(Context context, Set accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException { + public void exportPreferences(Context context, boolean includeGlobals, Set accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException { try { Log.i(K9.LOG_TAG, "Exporting preferences"); K9Krypto krypto = new K9Krypto(encryptionKey, K9Krypto.MODE.ENCRYPT); @@ -53,6 +53,9 @@ public class StorageExporterEncryptedXml implements IStorageExporter { //Log.i(K9.LOG_TAG, "Skipping key " + key + " which is not for any current account"); continue; } + } else if (!includeGlobals) { + // Skip global config entries if the user didn't request them + continue; } String keyEnc = krypto.encrypt(key); String valueEnc = krypto.encrypt(value);