@@ -32,7 +32,7 @@ pub const SingleMessageBody = union(enum) {
3232 text : []const u8 ,
3333 /// Writes the Content-Type as "text/html".
3434 html : []const u8 ,
35- /// Data structure that represent as email attachment.
35+ /// Data structure that represents as email attachment.
3636 attachment : Attachment ,
3737
3838 /// Formats the email message body into the expected header and content values.
@@ -140,9 +140,7 @@ pub const MultipartMessageBody = union(enum) {
140140
141141 try writer .writeAll ("\r \n " );
142142 }
143- }
144-
145- if (body .text ) | text_body | {
143+ } else if (body .text ) | text_body | {
146144 try writer .writeAll ("Content-Type: text/plain; charset=utf-8\r \n " );
147145 try writer .writeAll ("Content-Transfer-Encoding: quoted-printable\r \n \r \n " );
148146 try quotable_printable .encodeWriter (writer , text_body );
@@ -180,7 +178,7 @@ pub const MultipartMessageBody = union(enum) {
180178 try writer .writeAll ("\r \n " );
181179
182180 for (body .attachments ) | attachment | {
183- std .debug .assert (attachment == .inlined ); // Cannot send inlined email attachment in multipart/related
181+ std .debug .assert (attachment == .inlined ); // Cannot send non inlined email attachment in multipart/related
184182 try writer .print ("--{x}\r \n " , .{& boundary });
185183 try writer .print ("{f}" , .{attachment });
186184 }
@@ -212,9 +210,17 @@ pub const MessageBody = union(enum) {
212210/// Data structure that represent an email attachment that
213211/// can either be inlined or sent just as the attachment.
214212pub const Attachment = union (enum ) {
215- /// The attachment can be inlined in the email body.
213+ /// The attachment can be inlined in the email body if
214+ /// the email body is a html body.
215+ ///
216+ /// Example:
217+ ///
218+ /// ```zig
219+ /// const content_id = try std.fmt.bufPrint(&buffer, "{x}@{s}", .{ message_id.id, message_id.domain });
220+ /// const html = try std.fmt.bufPrint(&buffer1, "<img src=\"cid:{s}\" alt=\"Fooo\" />", .{content_id});
221+ /// ```
216222 inlined : struct {
217- content_id : [] const u8 ,
223+ content_id : MessageId ,
218224 body_contents : []const u8 ,
219225 content_type : []const u8 ,
220226 name : ? []const u8 ,
@@ -245,7 +251,7 @@ pub const Attachment = union(enum) {
245251 try writer .writeAll ("Content-Transfer-Encoding: base64\r \n " );
246252 try writer .print ("Content-Disposition: inline; filename={s}\r \n " , .{name });
247253 try writer .print ("Content-Location: {s};\r \n " , .{name });
248- try writer .print ("Content-Id: <{s}> \r \n \r \n " , .{content .content_id });
254+ try writer .print ("Content-Id: {f} \r \n \r \n " , .{content .content_id });
249255 try writer .print ("{b64}\r \n " , .{content .body_contents });
250256 } else {
251257 try writer .print ("Content-Type: {s};\r \n " , .{content .content_type });
0 commit comments