[geary] Tidy up Geary.Attachment API a bit.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Tidy up Geary.Attachment API a bit.
- Date: Wed, 15 Feb 2017 22:23:21 +0000 (UTC)
commit 6257e05ad9c478cb2c2447e13fd8729046cbd0f8
Author: Michael James Gratton <mike vee net>
Date: Sat Feb 11 09:52:23 2017 +1100
Tidy up Geary.Attachment API a bit.
* src/engine/api/geary-attachment.vala (Attachment): Allow direct access
to MIME content-disposition filename if available. Make it obvious that
the filename comes from content-disposition. Reorder attrs to reflect
importance. Update subclasses and call sites.
.../conversation-viewer/conversation-email.vala | 2 +-
src/engine/api/geary-attachment.vala | 84 +++++++++++---------
src/engine/imap-db/imap-db-attachment.vala | 27 +++++--
src/engine/imap-db/imap-db-folder.vala | 21 ++++--
4 files changed, 83 insertions(+), 51 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-email.vala
b/src/client/conversation-viewer/conversation-email.vala
index e24ff84..bd70da1 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -114,7 +114,7 @@ public class ConversationEmail : Gtk.Box {
);
string file_name = null;
- if (attachment.has_supplied_filename) {
+ if (attachment.has_content_filename) {
file_name = attachment.file.get_basename();
}
string file_desc = ContentType.get_description(gio_content_type);
diff --git a/src/engine/api/geary-attachment.vala b/src/engine/api/geary-attachment.vala
index fd6624c..82e64cf 100644
--- a/src/engine/api/geary-attachment.vala
+++ b/src/engine/api/geary-attachment.vala
@@ -11,69 +11,81 @@
*/
public abstract class Geary.Attachment : BaseObject {
+
/**
* An identifier that can be used to locate the {@link Attachment} in an {@link Email}.
*
* @see Email.get_attachment
*/
public string id { get; private set; }
-
- /**
- * Returns true if the originating {@link Email} supplied a filename for the {@link Attachment}.
- *
- * Since all files must have a name, one is supplied for the Attachment by Geary if this is
- * false. This is merely to indicate how the filename should be displayed, since Geary's will
- * be an untranslated "none".
- */
- public bool has_supplied_filename { get; private set; }
-
- /**
- * The on-disk File of the {@link Attachment}.
- */
- public File file { get; private set; }
-
+
/**
* The {@link Mime.ContentType} of the {@link Attachment}.
*/
public Mime.ContentType content_type { get; private set; }
-
+
/**
- * The file size (in bytes) if the {@link file}.
+ * The Content-ID of the attachment.
+ *
+ * See [[https://tools.ietf.org/html/rfc2111]]
*/
- public int64 filesize { get; private set; }
-
+ public string? content_id { get; private set; }
+
+ /**
+ * The Content-Description of the attachment.
+ *
+ * See [[https://tools.ietf.org/html/rfc2045#section-8]]
+ */
+ public string? content_description { get; private set; }
+
/**
* The {@link Mime.ContentDisposition} of the attachment, as specified by the {@link Email}.
*
* See [[https://tools.ietf.org/html/rfc2183]]
*/
public Mime.ContentDisposition content_disposition { get; private set; }
-
+
/**
- * The Content-ID of the attachment.
+ * Returns true if a filename was supplied in {@link content_disposition}.
*
- * See [[https://tools.ietf.org/html/rfc2111]]
+ * Since all files must have a name, one is supplied for the
+ * Attachment by Geary if this is false. This is merely to
+ * indicate how the filename should be displayed, since Geary's
+ * will be an untranslated "none".
*/
- public string? content_id { get; private set; }
-
+ public bool has_content_filename { get { return this.content_filename != null; } }
+
/**
- * The Content-Description of the attachment.
- *
- * See [[https://tools.ietf.org/html/rfc2045#section-8]]
+ * The filename supplied in {@link content_disposition}, if any.
*/
- public string? content_description { get; private set; }
-
- protected Attachment(string id, File file, bool has_supplied_filename, Mime.ContentType content_type,
- int64 filesize, Mime.ContentDisposition content_disposition, string? content_id,
- string? content_description) {
+ public string? content_filename { get; private set; }
+
+ /**
+ * The on-disk File of the {@link Attachment}.
+ */
+ public File file { get; private set; }
+
+ /**
+ * The file size (in bytes) if the {@link file}.
+ */
+ public int64 filesize { get; private set; }
+
+ protected Attachment(string id,
+ Mime.ContentType content_type,
+ string? content_id,
+ string? content_description,
+ Mime.ContentDisposition content_disposition,
+ string? content_filename,
+ File file,
+ int64 filesize) {
this.id = id;
- this.file = file;
- this.has_supplied_filename = has_supplied_filename;
this.content_type = content_type;
- this.filesize = filesize;
- this.content_disposition = content_disposition;
this.content_id = content_id;
this.content_description = content_description;
+ this.content_disposition = content_disposition;
+ this.content_filename = content_filename;
+ this.file = file;
+ this.filesize = filesize;
}
}
diff --git a/src/engine/imap-db/imap-db-attachment.vala b/src/engine/imap-db/imap-db-attachment.vala
index c032a50..7ed57f3 100644
--- a/src/engine/imap-db/imap-db-attachment.vala
+++ b/src/engine/imap-db/imap-db-attachment.vala
@@ -8,15 +8,26 @@ private class Geary.ImapDB.Attachment : Geary.Attachment {
public const Email.Field REQUIRED_FIELDS = Email.REQUIRED_FOR_MESSAGE;
private const string ATTACHMENTS_DIR = "attachments";
-
- public Attachment(File data_dir, string? filename, Mime.ContentType content_type, int64 filesize,
- int64 message_id, int64 attachment_id, Mime.ContentDisposition content_disposition,
- string? content_id, string? content_description) {
- base (generate_id(attachment_id),generate_file(data_dir, message_id, attachment_id, filename),
- !String.is_empty(filename), content_type, filesize, content_disposition, content_id,
- content_description);
+
+ public Attachment(int64 message_id,
+ int64 attachment_id,
+ Mime.ContentType content_type,
+ string? content_id,
+ string? content_description,
+ Mime.ContentDisposition content_disposition,
+ string? content_filename,
+ File data_dir,
+ int64 filesize) {
+ base (generate_id(attachment_id),
+ content_type,
+ content_id,
+ content_description,
+ content_disposition,
+ content_filename,
+ generate_file(data_dir, message_id, attachment_id, content_filename),
+ filesize);
}
-
+
private static string generate_id(int64 attachment_id) {
return "imap-db:%s".printf(attachment_id.to_string());
}
diff --git a/src/engine/imap-db/imap-db-folder.vala b/src/engine/imap-db/imap-db-folder.vala
index 18d0123..f7d0d7a 100644
--- a/src/engine/imap-db/imap-db-folder.vala
+++ b/src/engine/imap-db/imap-db-folder.vala
@@ -2006,17 +2006,26 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics {
Db.Result results = stmt.exec(cancellable);
if (results.finished)
return null;
-
+
Gee.List<Geary.Attachment> list = new Gee.ArrayList<Geary.Attachment>();
do {
Mime.ContentDisposition disposition = new Mime.ContentDisposition.simple(
Mime.DispositionType.from_int(results.int_at(4)));
- list.add(new ImapDB.Attachment(cx.database.db_file.get_parent(), results.string_at(1),
- Mime.ContentType.deserialize(results.nonnull_string_at(2)), results.int64_at(3),
- message_id, results.rowid_at(0), disposition, results.string_at(5),
- results.string_at(6)));
+ list.add(
+ new ImapDB.Attachment(
+ message_id,
+ results.rowid_at(0),
+ Mime.ContentType.deserialize(results.nonnull_string_at(2)),
+ results.string_at(5),
+ results.string_at(6),
+ disposition,
+ results.string_at(1),
+ cx.database.db_file.get_parent(),
+ results.int64_at(3)
+ )
+ );
} while (results.next(cancellable));
-
+
return list;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]