[geary/wip/362-utf8-attachments: 1/3] Remove Geary.RFC822.Part.get_effective_content_type
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/362-utf8-attachments: 1/3] Remove Geary.RFC822.Part.get_effective_content_type
- Date: Thu, 18 Jul 2019 04:50:53 +0000 (UTC)
commit 6a871c25c63668aebed1df32853956d724c7ea9b
Author: Michael Gratton <mike vee net>
Date: Thu Jul 18 14:34:19 2019 +1000
Remove Geary.RFC822.Part.get_effective_content_type
Just make the `content_type` property non-nullable and set a default
in the ctor instead, since it's unlikely to ever be null despite the
GMime API suggesting it could be. Update call sites to use the property
instead.
.../conversation-viewer/conversation-message.vala | 2 +-
src/engine/imap-db/imap-db-attachment.vala | 2 +-
src/engine/rfc822/rfc822-message-data.vala | 2 +-
src/engine/rfc822/rfc822-message.vala | 8 ++----
src/engine/rfc822/rfc822-part.vala | 32 ++++++++--------------
test/engine/rfc822-part-test.vala | 10 ++-----
6 files changed, 20 insertions(+), 36 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-message.vala
b/src/client/conversation-viewer/conversation-message.vala
index be2237c8..c8fef70b 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -929,7 +929,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
// returns HTML that is placed into the document in the position
// where the MIME part was found
private string? inline_image_replacer(Geary.RFC822.Part part) {
- Geary.Mime.ContentType content_type = part.get_effective_content_type();
+ Geary.Mime.ContentType content_type = part.content_type;
if (content_type.media_type != "image" ||
!this.web_view.can_show_mime_type(content_type.to_string())) {
debug("Not displaying %s inline: unsupported Content-Type",
diff --git a/src/engine/imap-db/imap-db-attachment.vala b/src/engine/imap-db/imap-db-attachment.vala
index 60c7028c..540222d7 100644
--- a/src/engine/imap-db/imap-db-attachment.vala
+++ b/src/engine/imap-db/imap-db-attachment.vala
@@ -46,7 +46,7 @@ private class Geary.ImapDB.Attachment : Geary.Attachment {
this(
message_id,
- part.get_effective_content_type(),
+ part.content_type,
part.content_id,
part.content_description,
disposition,
diff --git a/src/engine/rfc822/rfc822-message-data.vala b/src/engine/rfc822/rfc822-message-data.vala
index be14de3c..9476ce78 100644
--- a/src/engine/rfc822/rfc822-message-data.vala
+++ b/src/engine/rfc822/rfc822-message-data.vala
@@ -396,7 +396,7 @@ public class Geary.RFC822.PreviewText : Geary.RFC822.Text {
if (gpart != null) {
Part part = new Part(gpart);
- Mime.ContentType content_type = part.get_effective_content_type();
+ Mime.ContentType content_type = part.content_type;
bool is_plain = content_type.is_type("text", "plain");
bool is_html = content_type.is_type("text", "html");
diff --git a/src/engine/rfc822/rfc822-message.vala b/src/engine/rfc822/rfc822-message.vala
index 2f171fef..9eba825b 100644
--- a/src/engine/rfc822/rfc822-message.vala
+++ b/src/engine/rfc822/rfc822-message.vala
@@ -519,7 +519,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
is_matching_part = (
disposition != Mime.DispositionType.ATTACHMENT &&
- part.get_effective_content_type().is_type("text", text_subtype)
+ part.content_type.is_type("text", text_subtype)
);
}
return is_matching_part;
@@ -549,7 +549,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
ref string? body)
throws RFC822Error {
Part part = new Part(node);
- Mime.ContentType content_type = part.get_effective_content_type();
+ Mime.ContentType content_type = part.content_type;
// If this is a multipart, call ourselves recursively on the children
GMime.Multipart? multipart = node as GMime.Multipart;
@@ -876,9 +876,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
if (requested_disposition == Mime.DispositionType.UNSPECIFIED ||
actual_disposition == requested_disposition) {
-
- Mime.ContentType content_type =
- part.get_effective_content_type();
+ Mime.ContentType content_type = part.content_type;
#if WITH_TNEF_SUPPORT
if (content_type.is_type("application", "vnd.ms-tnef")) {
diff --git a/src/engine/rfc822/rfc822-part.vala b/src/engine/rfc822/rfc822-part.vala
index 82c2f6d9..c7d941fd 100644
--- a/src/engine/rfc822/rfc822-part.vala
+++ b/src/engine/rfc822/rfc822-part.vala
@@ -52,7 +52,7 @@ public class Geary.RFC822.Part : Object {
*
* See [[https://tools.ietf.org/html/rfc2045#section-5]]
*/
- public Mime.ContentType? content_type { get; private set; }
+ public Mime.ContentType content_type { get; private set; }
/**
* The entity's Content-ID.
@@ -85,44 +85,34 @@ public class Geary.RFC822.Part : Object {
this.source_object = source;
this.source_part = source as GMime.Part;
- GMime.ContentType? part_type = source.get_content_type();
- if (part_type != null) {
- this.content_type = new Mime.ContentType.from_gmime(part_type);
- }
-
this.content_id = source.get_content_id();
this.content_description = (this.source_part != null)
? source_part.get_content_description() : null;
- GMime.ContentDisposition? part_disposition = source.get_content_disposition();
+ GMime.ContentDisposition? part_disposition =
+ source.get_content_disposition();
if (part_disposition != null) {
this.content_disposition = new Mime.ContentDisposition.from_gmime(
part_disposition
);
}
- }
- /**
- * The entity's effective Content-Type.
- *
- * This returns the entity's content type if set, else returns
- * {@link Geary.Mime.ContentType.DISPLAY_DEFAULT} this is a
- * displayable (i.e. non-attachment) entity, or {@link
- * Geary.Mime.ContentType.ATTACHMENT_DEFAULT} if not.
- */
- public Mime.ContentType get_effective_content_type() {
- Mime.ContentType? type = this.content_type;
- if (type == null) {
+ // Although the GMime API permits this to be null, it's not
+ // clear if it ever will be, since the API requires it to be
+ // specified at construction time.
+ GMime.ContentType? part_type = source.get_content_type();
+ if (part_type != null) {
+ this.content_type = new Mime.ContentType.from_gmime(part_type);
+ } else {
Mime.DispositionType disposition = Mime.DispositionType.UNSPECIFIED;
if (this.content_disposition != null) {
disposition = this.content_disposition.disposition_type;
}
- type = (disposition != Mime.DispositionType.ATTACHMENT)
+ this.content_type = (disposition != Mime.DispositionType.ATTACHMENT)
? Mime.ContentType.DISPLAY_DEFAULT
: Mime.ContentType.ATTACHMENT_DEFAULT;
}
- return type;
}
/**
diff --git a/test/engine/rfc822-part-test.vala b/test/engine/rfc822-part-test.vala
index 4a0a2640..ab5f026e 100644
--- a/test/engine/rfc822-part-test.vala
+++ b/test/engine/rfc822-part-test.vala
@@ -14,20 +14,16 @@ class Geary.RFC822.PartTest : TestCase {
public PartTest() {
base("Geary.RFC822.PartTest");
- add_test("new_from_empty_mime_part", new_from_empty_mime_part);
+ add_test("new_from_minimal_mime_part", new_from_minimal_mime_part);
add_test("new_from_complete_mime_part", new_from_complete_mime_part);
add_test("write_to_buffer_plain", write_to_buffer_plain);
add_test("write_to_buffer_plain_crlf", write_to_buffer_plain_crlf);
add_test("write_to_buffer_plain_ical", write_to_buffer_plain_ical);
}
- public void new_from_empty_mime_part() throws Error {
- GMime.Part part = new_part(null, CR_BODY.data);
- part.set_header("Content-Type", "");
+ public void new_from_minimal_mime_part() throws Error {
+ Part test = new Part(new_part("test/plain", CR_BODY.data));
- Part test = new Part(part);
-
- assert_null(test.content_type, "content_type");
assert_null_string(test.content_id, "content_id");
assert_null_string(test.content_description, "content_description");
assert_null(test.content_disposition, "content_disposition");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]