mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-17 07:30:16 -05:00
More structure for the XML export (identity)
This commit is contained in:
parent
77f7303aa2
commit
24785bab66
@ -22,10 +22,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -53,6 +55,16 @@ public class Account implements BaseAccount {
|
|||||||
private static final String DEFAULT_QUOTE_PREFIX = ">";
|
private static final String DEFAULT_QUOTE_PREFIX = ">";
|
||||||
private static final boolean DEFAULT_REPLY_AFTER_QUOTE = false;
|
private static final boolean DEFAULT_REPLY_AFTER_QUOTE = false;
|
||||||
|
|
||||||
|
public static final Set<String> IDENTITY_KEYS = new HashSet<String>();
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 0 - Never (DELETE_POLICY_NEVER)
|
* 0 - Never (DELETE_POLICY_NEVER)
|
||||||
@ -1018,7 +1030,6 @@ public class Account implements BaseAccount {
|
|||||||
return mUuid.hashCode();
|
return mUuid.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private synchronized List<Identity> loadIdentities(SharedPreferences prefs) {
|
private synchronized List<Identity> loadIdentities(SharedPreferences prefs) {
|
||||||
List<Identity> newIdentities = new ArrayList<Identity>();
|
List<Identity> newIdentities = new ArrayList<Identity>();
|
||||||
int ident = 0;
|
int ident = 0;
|
||||||
|
@ -29,6 +29,8 @@ public class StorageExporter {
|
|||||||
private static final String SETTINGS_ELEMENT = "settings";
|
private static final String SETTINGS_ELEMENT = "settings";
|
||||||
private static final String ACCOUNTS_ELEMENT = "accounts";
|
private static final String ACCOUNTS_ELEMENT = "accounts";
|
||||||
private static final String ACCOUNT_ELEMENT = "account";
|
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 UUID_ATTRIBUTE = "uuid";
|
||||||
private static final String VALUE_ELEMENT = "value";
|
private static final String VALUE_ELEMENT = "value";
|
||||||
private static final String KEY_ATTRIBUTE = "key";
|
private static final String KEY_ATTRIBUTE = "key";
|
||||||
@ -133,19 +135,34 @@ public class StorageExporter {
|
|||||||
private static void writeAccount(XmlSerializer serializer, String accountUuid,
|
private static void writeAccount(XmlSerializer serializer, String accountUuid,
|
||||||
Map<String, ? extends Object> prefs) throws IOException {
|
Map<String, ? extends Object> prefs) throws IOException {
|
||||||
|
|
||||||
|
Set<String> identities = new HashSet<String>();
|
||||||
|
|
||||||
serializer.startTag(null, ACCOUNT_ELEMENT);
|
serializer.startTag(null, ACCOUNT_ELEMENT);
|
||||||
serializer.attribute(null, UUID_ATTRIBUTE, accountUuid);
|
serializer.attribute(null, UUID_ATTRIBUTE, accountUuid);
|
||||||
|
|
||||||
|
serializer.startTag(null, SETTINGS_ELEMENT);
|
||||||
for (Map.Entry<String, ? extends Object> entry : prefs.entrySet()) {
|
for (Map.Entry<String, ? extends Object> entry : prefs.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
String value = entry.getValue().toString();
|
String value = entry.getValue().toString();
|
||||||
String[] comps = key.split("\\.");
|
String[] comps = key.split("\\.");
|
||||||
if (comps.length > 1) {
|
if (comps.length >= 2) {
|
||||||
String keyUuid = comps[0];
|
String keyUuid = comps[0];
|
||||||
if (!keyUuid.equals(accountUuid)) {
|
if (!keyUuid.equals(accountUuid)) {
|
||||||
continue;
|
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 {
|
} else {
|
||||||
// Skip global config entries
|
// Skip global config entries and identity entries
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,6 +174,45 @@ public class StorageExporter {
|
|||||||
serializer.text(value);
|
serializer.text(value);
|
||||||
serializer.endTag(null, VALUE_ELEMENT);
|
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);
|
serializer.endTag(null, ACCOUNT_ELEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void writeIdentity(XmlSerializer serializer, String accountUuid,
|
||||||
|
String identity, Map<String, ? extends Object> prefs) throws IOException {
|
||||||
|
|
||||||
|
serializer.startTag(null, IDENTITY_ELEMENT);
|
||||||
|
for (Map.Entry<String, ? extends Object> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user