sendr/message/attachment
This module provides a lax representation of an attachment as defined in RFC 2045.
It does not enforce any of the rules and requirements of the RFC. Since we do not know what transformations the Mail Submission Agent will perform and what the Mail Submission Agent is capable of handling.
Types
The attachment structure.
Represents an attachment. This structure is used to handle attachments in a flexible manner, adhering to a lax interpretation of RFC 2045.
pub type Attachment {
AttachedAttachment(
content_type: String,
filename: String,
filename_utf8: String,
data: BitArray,
)
InlinedAttachment(
content_type: String,
filename: String,
filename_utf8: String,
data: BitArray,
content_id: String,
)
}
Constructors
-
AttachedAttachment( content_type: String, filename: String, filename_utf8: String, data: BitArray, ) -
InlinedAttachment( content_type: String, filename: String, filename_utf8: String, data: BitArray, content_id: String, )
Values
pub fn from_data(
file path: String,
data data: BitArray,
) -> Attachment
Create a new attachment from raw data.
This function allows creating an attachment directly from binary data. It is useful when the attachment data is already available in memory.
pub fn from_file(
file path: String,
) -> Result(Attachment, simplifile.FileError)
Create a new attachment from a file.
This function reads the file, determines its content type based on its extension, and creates an attachment with the file’s data. If the content type cannot be determined, it defaults to “application/octet-stream”.
pub fn set_content_id(
of attachment: Attachment,
to content_id: String,
) -> Attachment
Set the content-id on the attachment.
The content ID is used to uniquely identify the attachment within the message. This is particularly useful for referencing the attachment in the message body.
pub fn set_content_type(
of attachment: Attachment,
to content_type: String,
) -> Attachment
Set the content-type on the attachment.
The content type specifies the type of data contained in the attachment. This helps the recipient’s system to handle the attachment appropriately.
pub fn set_filename(
of attachment: Attachment,
to path: String,
update_content_type update: Bool,
) -> Attachment
Set the filename on the attachment (for ASCII filenames).
Optionally also updates the content type.
The filename is used to suggest a name for the attachment when it is saved by the recipient. This is particularly useful for attachments that are intended to be downloaded or saved.
pub fn set_filename_utf8(
of attachment: Attachment,
to path: String,
update_content_type update: Bool,
) -> Attachment
Set the filename_utf8 on the attachment (for UTF-8 filenames).
Optionally also updates the content type.
The filename is used to suggest a name for the attachment when it is saved by the recipient. This is particularly useful for attachments that are intended to be downloaded or saved.