diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index f868e1a88..1bc83e8ed 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -22,10 +22,12 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -53,6 +55,16 @@ public class Account implements BaseAccount { private static final String DEFAULT_QUOTE_PREFIX = ">"; private static final boolean DEFAULT_REPLY_AFTER_QUOTE = false; + public static final Set IDENTITY_KEYS = new HashSet(); + static { + IDENTITY_KEYS.add("name"); + IDENTITY_KEYS.add("email"); + IDENTITY_KEYS.add("description"); + IDENTITY_KEYS.add("signatureUse"); + IDENTITY_KEYS.add("signature"); + IDENTITY_KEYS.add("replyTo"); + } + /** *
      * 0 - Never (DELETE_POLICY_NEVER)
@@ -1018,7 +1030,6 @@ public class Account implements BaseAccount {
         return mUuid.hashCode();
     }
 
-
     private synchronized List loadIdentities(SharedPreferences prefs) {
         List newIdentities = new ArrayList();
         int ident = 0;
diff --git a/src/com/fsck/k9/preferences/StorageExporter.java b/src/com/fsck/k9/preferences/StorageExporter.java
index f7396ec04..01a2625a1 100644
--- a/src/com/fsck/k9/preferences/StorageExporter.java
+++ b/src/com/fsck/k9/preferences/StorageExporter.java
@@ -29,6 +29,8 @@ public class StorageExporter {
     private static final String SETTINGS_ELEMENT = "settings";
     private static final String ACCOUNTS_ELEMENT = "accounts";
     private static final String ACCOUNT_ELEMENT = "account";
+    private static final String IDENTITIES_ELEMENT = "identities";
+    private static final String IDENTITY_ELEMENT = "identity";
     private static final String UUID_ATTRIBUTE = "uuid";
     private static final String VALUE_ELEMENT = "value";
     private static final String KEY_ATTRIBUTE = "key";
@@ -133,19 +135,34 @@ public class StorageExporter {
     private static void writeAccount(XmlSerializer serializer, String accountUuid,
             Map prefs) throws IOException {
 
+        Set identities = new HashSet();
+
         serializer.startTag(null, ACCOUNT_ELEMENT);
         serializer.attribute(null, UUID_ATTRIBUTE, accountUuid);
+
+        serializer.startTag(null, SETTINGS_ELEMENT);
         for (Map.Entry entry : prefs.entrySet()) {
             String key = entry.getKey();
             String value = entry.getValue().toString();
             String[] comps = key.split("\\.");
-            if (comps.length > 1) {
+            if (comps.length >= 2) {
                 String keyUuid = comps[0];
                 if (!keyUuid.equals(accountUuid)) {
                     continue;
                 }
+                if (comps.length == 3) {
+                    String identityKey = comps[1];
+                    String identityIndex = comps[2];
+
+                    if (Account.IDENTITY_KEYS.contains(identityKey)) {
+                        // This is an identity key. Save identity index for later...
+                        identities.add(identityIndex);
+                        // ... but don't write it now.
+                        continue;
+                    }
+                }
             } else {
-                // Skip global config entries
+                // Skip global config entries and identity entries
                 continue;
             }
 
@@ -157,6 +174,45 @@ public class StorageExporter {
             serializer.text(value);
             serializer.endTag(null, VALUE_ELEMENT);
         }
+        serializer.endTag(null, SETTINGS_ELEMENT);
+
+        if (identities.size() > 0) {
+            serializer.startTag(null, IDENTITIES_ELEMENT);
+            for (String identityIndex : identities) {
+                writeIdentity(serializer, accountUuid, identityIndex, prefs);
+            }
+            serializer.endTag(null, IDENTITIES_ELEMENT);
+        }
+
         serializer.endTag(null, ACCOUNT_ELEMENT);
     }
+
+    private static void writeIdentity(XmlSerializer serializer, String accountUuid,
+            String identity, Map prefs) throws IOException {
+
+        serializer.startTag(null, IDENTITY_ELEMENT);
+        for (Map.Entry entry : prefs.entrySet()) {
+            String key = entry.getKey();
+            String value = entry.getValue().toString();
+            String[] comps = key.split("\\.");
+            if (comps.length >= 3) {
+                String keyUuid = comps[0];
+                String identityKey = comps[1];
+                String identityIndex = comps[2];
+                if (!keyUuid.equals(accountUuid) || !identityIndex.equals(identity)
+                        || !Account.IDENTITY_KEYS.contains(identityKey)) {
+                    continue;
+                }
+            } else {
+                // Skip non-identity config entries
+                continue;
+            }
+
+            serializer.startTag(null, VALUE_ELEMENT);
+            serializer.attribute(null, KEY_ATTRIBUTE, comps[1]);
+            serializer.text(value);
+            serializer.endTag(null, VALUE_ELEMENT);
+        }
+        serializer.endTag(null, IDENTITY_ELEMENT);
+    }
 }