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.
This commit is contained in:
parent
88efd14a82
commit
6a871c25c6
6 changed files with 20 additions and 36 deletions
|
|
@ -929,7 +929,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
|
||||||
// returns HTML that is placed into the document in the position
|
// returns HTML that is placed into the document in the position
|
||||||
// where the MIME part was found
|
// where the MIME part was found
|
||||||
private string? inline_image_replacer(Geary.RFC822.Part part) {
|
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" ||
|
if (content_type.media_type != "image" ||
|
||||||
!this.web_view.can_show_mime_type(content_type.to_string())) {
|
!this.web_view.can_show_mime_type(content_type.to_string())) {
|
||||||
debug("Not displaying %s inline: unsupported Content-Type",
|
debug("Not displaying %s inline: unsupported Content-Type",
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ private class Geary.ImapDB.Attachment : Geary.Attachment {
|
||||||
|
|
||||||
this(
|
this(
|
||||||
message_id,
|
message_id,
|
||||||
part.get_effective_content_type(),
|
part.content_type,
|
||||||
part.content_id,
|
part.content_id,
|
||||||
part.content_description,
|
part.content_description,
|
||||||
disposition,
|
disposition,
|
||||||
|
|
|
||||||
|
|
@ -396,7 +396,7 @@ public class Geary.RFC822.PreviewText : Geary.RFC822.Text {
|
||||||
if (gpart != null) {
|
if (gpart != null) {
|
||||||
Part part = new Part(gpart);
|
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_plain = content_type.is_type("text", "plain");
|
||||||
bool is_html = content_type.is_type("text", "html");
|
bool is_html = content_type.is_type("text", "html");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -519,7 +519,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
|
||||||
|
|
||||||
is_matching_part = (
|
is_matching_part = (
|
||||||
disposition != Mime.DispositionType.ATTACHMENT &&
|
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;
|
return is_matching_part;
|
||||||
|
|
@ -549,7 +549,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
|
||||||
ref string? body)
|
ref string? body)
|
||||||
throws RFC822Error {
|
throws RFC822Error {
|
||||||
Part part = new Part(node);
|
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
|
// If this is a multipart, call ourselves recursively on the children
|
||||||
GMime.Multipart? multipart = node as GMime.Multipart;
|
GMime.Multipart? multipart = node as GMime.Multipart;
|
||||||
|
|
@ -876,9 +876,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
|
||||||
|
|
||||||
if (requested_disposition == Mime.DispositionType.UNSPECIFIED ||
|
if (requested_disposition == Mime.DispositionType.UNSPECIFIED ||
|
||||||
actual_disposition == requested_disposition) {
|
actual_disposition == requested_disposition) {
|
||||||
|
Mime.ContentType content_type = part.content_type;
|
||||||
Mime.ContentType content_type =
|
|
||||||
part.get_effective_content_type();
|
|
||||||
|
|
||||||
#if WITH_TNEF_SUPPORT
|
#if WITH_TNEF_SUPPORT
|
||||||
if (content_type.is_type("application", "vnd.ms-tnef")) {
|
if (content_type.is_type("application", "vnd.ms-tnef")) {
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ public class Geary.RFC822.Part : Object {
|
||||||
*
|
*
|
||||||
* See [[https://tools.ietf.org/html/rfc2045#section-5]]
|
* 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.
|
* The entity's Content-ID.
|
||||||
|
|
@ -85,44 +85,34 @@ public class Geary.RFC822.Part : Object {
|
||||||
this.source_object = source;
|
this.source_object = source;
|
||||||
this.source_part = source as GMime.Part;
|
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_id = source.get_content_id();
|
||||||
|
|
||||||
this.content_description = (this.source_part != null)
|
this.content_description = (this.source_part != null)
|
||||||
? source_part.get_content_description() : 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) {
|
if (part_disposition != null) {
|
||||||
this.content_disposition = new Mime.ContentDisposition.from_gmime(
|
this.content_disposition = new Mime.ContentDisposition.from_gmime(
|
||||||
part_disposition
|
part_disposition
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Although the GMime API permits this to be null, it's not
|
||||||
* The entity's effective Content-Type.
|
// clear if it ever will be, since the API requires it to be
|
||||||
*
|
// specified at construction time.
|
||||||
* This returns the entity's content type if set, else returns
|
GMime.ContentType? part_type = source.get_content_type();
|
||||||
* {@link Geary.Mime.ContentType.DISPLAY_DEFAULT} this is a
|
if (part_type != null) {
|
||||||
* displayable (i.e. non-attachment) entity, or {@link
|
this.content_type = new Mime.ContentType.from_gmime(part_type);
|
||||||
* Geary.Mime.ContentType.ATTACHMENT_DEFAULT} if not.
|
} else {
|
||||||
*/
|
|
||||||
public Mime.ContentType get_effective_content_type() {
|
|
||||||
Mime.ContentType? type = this.content_type;
|
|
||||||
if (type == null) {
|
|
||||||
Mime.DispositionType disposition = Mime.DispositionType.UNSPECIFIED;
|
Mime.DispositionType disposition = Mime.DispositionType.UNSPECIFIED;
|
||||||
if (this.content_disposition != null) {
|
if (this.content_disposition != null) {
|
||||||
disposition = this.content_disposition.disposition_type;
|
disposition = this.content_disposition.disposition_type;
|
||||||
}
|
}
|
||||||
type = (disposition != Mime.DispositionType.ATTACHMENT)
|
this.content_type = (disposition != Mime.DispositionType.ATTACHMENT)
|
||||||
? Mime.ContentType.DISPLAY_DEFAULT
|
? Mime.ContentType.DISPLAY_DEFAULT
|
||||||
: Mime.ContentType.ATTACHMENT_DEFAULT;
|
: Mime.ContentType.ATTACHMENT_DEFAULT;
|
||||||
}
|
}
|
||||||
return type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,20 +14,16 @@ class Geary.RFC822.PartTest : TestCase {
|
||||||
|
|
||||||
public PartTest() {
|
public PartTest() {
|
||||||
base("Geary.RFC822.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("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", write_to_buffer_plain);
|
||||||
add_test("write_to_buffer_plain_crlf", write_to_buffer_plain_crlf);
|
add_test("write_to_buffer_plain_crlf", write_to_buffer_plain_crlf);
|
||||||
add_test("write_to_buffer_plain_ical", write_to_buffer_plain_ical);
|
add_test("write_to_buffer_plain_ical", write_to_buffer_plain_ical);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void new_from_empty_mime_part() throws Error {
|
public void new_from_minimal_mime_part() throws Error {
|
||||||
GMime.Part part = new_part(null, CR_BODY.data);
|
Part test = new Part(new_part("test/plain", CR_BODY.data));
|
||||||
part.set_header("Content-Type", "");
|
|
||||||
|
|
||||||
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_id, "content_id");
|
||||||
assert_null_string(test.content_description, "content_description");
|
assert_null_string(test.content_description, "content_description");
|
||||||
assert_null(test.content_disposition, "content_disposition");
|
assert_null(test.content_disposition, "content_disposition");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue