geary/src/engine/imap-db/imap-db-attachment.vala
Jim Nelson ddc6403aad Cleaned up Geary.Attachments implementation and interface
While working on #7345, I grew dissatisfied with how Geary.Attachment
was implemented.  It knew too much about imap-db's internal workings,
so I've broken it up a little bit.  It's now an abstract base class
completed by ImapDB.Attachment, a private implementation class.
This corresponds with the coding patterns used throughout the
Geary API.
2013-09-09 15:05:22 -07:00

35 lines
1.5 KiB
Vala

/* Copyright 2013 Yorba Foundation
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
private class Geary.ImapDB.Attachment : Geary.Attachment {
public const Email.Field REQUIRED_FIELDS = Email.REQUIRED_FOR_MESSAGE;
private const string ATTACHMENTS_DIR = "attachments";
protected Attachment(File data_dir, string? filename, string mime_type, int64 filesize,
int64 message_id, int64 attachment_id, Geary.Attachment.Disposition disposition) {
base (generate_id(attachment_id),generate_file(data_dir, message_id, attachment_id, filename),
!String.is_empty(filename), mime_type, filesize, disposition);
}
private static string generate_id(int64 attachment_id) {
return "imap-db:%s".printf(attachment_id.to_string());
}
public static File generate_file(File data_dir, int64 message_id, int64 attachment_id,
string? filename) {
// "none" should not be translated, or the user will be unable to retrieve their
// attachments with no filenames after changing their language.
return get_attachments_dir(data_dir)
.get_child(message_id.to_string())
.get_child(attachment_id.to_string())
.get_child(filename ?? "none");
}
public static File get_attachments_dir(File data_dir) {
return data_dir.get_child(ATTACHMENTS_DIR);
}
}