Make serialisation of Geary.Email.Field more usable

This commit is contained in:
Michael Gratton 2019-11-01 15:48:19 +11:00
parent 39b5f7922b
commit 47927aaff4
3 changed files with 39 additions and 21 deletions

View file

@ -157,18 +157,25 @@ public class Geary.Email : BaseObject, EmailHeaderSet {
return is_any_set(required_fields);
}
public string to_list_string() {
StringBuilder builder = new StringBuilder();
foreach (Field f in all()) {
if (is_all_set(f)) {
if (!String.is_empty(builder.str))
builder.append(", ");
builder.append(f.to_string());
public string to_string() {
string value = "NONE";
if (this == ALL) {
value = "ALL";
} else if (this > 0) {
StringBuilder builder = new StringBuilder();
foreach (Field f in all()) {
if (is_all_set(f)) {
if (!String.is_empty(builder.str)) {
builder.append(",");
}
builder.append(
ObjectUtils.to_enum_nick(typeof(Field), f).up()
);
}
}
value = builder.str;
}
return builder.str;
return value;
}
}

View file

@ -1288,10 +1288,11 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics {
int64 id = -1;
// if fields not present, then no duplicate can reliably be found
if (!email.fields.is_all_set(REQUIRED_FIELDS)) {
debug("%s: Unable to detect duplicates for %s, fields available: %s",
this.to_string(),
email.id.to_string(),
email.fields.to_list_string()
debug(
"%s: Unable to detect duplicates for %s, fields available: %s",
this.to_string(),
email.id.to_string(),
email.fields.to_string()
);
return id;
}
@ -1304,8 +1305,11 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics {
int64 rfc822_size = (imap_properties != null) ? imap_properties.rfc822_size.value : -1;
if (String.is_empty(internaldate) || rfc822_size < 0) {
debug("Unable to detect duplicates for %s (%s available but invalid)", email.id.to_string(),
email.fields.to_list_string());
debug(
"Unable to detect duplicates for %s (%s available but invalid)",
email.id.to_string(),
email.fields.to_string()
);
return id;
}

View file

@ -497,8 +497,11 @@ private class Geary.Imap.FolderSession : Geary.Imap.SessionObject {
out preview_charset_specifier
);
if (cmds.size == 0) {
throw new ImapError.INVALID("No FETCH commands generate for list request %s %s",
msg_set.to_string(), fields.to_list_string());
throw new ImapError.INVALID(
"No FETCH commands generate for list request %s %s",
msg_set.to_string(),
fields.to_string()
);
}
// Commands prepped, do the fetch and accumulate all the responses
@ -549,9 +552,13 @@ private class Geary.Imap.FolderSession : Geary.Imap.SessionObject {
preview_charset_specifier
);
if (!email.fields.fulfills(fields)) {
message("%s: %s missing=%s fetched=%s", to_string(), email.id.to_string(),
fields.clear(email.fields).to_list_string(), fetched_data.to_string());
message(
"%s: %s missing=%s fetched=%s",
to_string(),
email.id.to_string(),
fields.clear(email.fields).to_string(),
fetched_data.to_string()
);
continue;
}