@@ -37,13 +37,15 @@ impl AttachmentType {
37
37
}
38
38
}
39
39
40
- #[ derive( Clone , PartialEq ) ]
40
+ #[ derive( Clone , PartialEq , Default ) ]
41
41
/// Represents an attachment item.
42
42
pub struct Attachment {
43
43
/// The actual attachment data.
44
44
pub buffer : Vec < u8 > ,
45
45
/// The filename of the attachment.
46
46
pub filename : String ,
47
+ /// The Content Type of the attachment
48
+ pub content_type : Option < String > ,
47
49
/// The special type of this attachment.
48
50
pub ty : Option < AttachmentType > ,
49
51
}
@@ -56,10 +58,14 @@ impl Attachment {
56
58
{
57
59
writeln ! (
58
60
writer,
59
- r#"{{"type":"attachment","length":{length},"filename":"{filename}","attachment_type":"{at}"}}"# ,
61
+ r#"{{"type":"attachment","length":{length},"filename":"{filename}","attachment_type":"{at}","content_type":"{ct}" }}"# ,
60
62
filename = self . filename,
61
63
length = self . buffer. len( ) ,
62
- at = self . ty. unwrap_or_default( ) . as_str( )
64
+ at = self . ty. unwrap_or_default( ) . as_str( ) ,
65
+ ct = self
66
+ . content_type
67
+ . as_ref( )
68
+ . unwrap_or( & "application/octet-stream" . to_string( ) )
63
69
) ?;
64
70
65
71
writer. write_all ( & self . buffer ) ?;
@@ -74,6 +80,7 @@ impl fmt::Debug for Attachment {
74
80
f. debug_struct ( "Attachment" )
75
81
. field ( "buffer" , & self . buffer . len ( ) )
76
82
. field ( "filename" , & self . filename )
83
+ . field ( "content_type" , & self . content_type )
77
84
. field ( "type" , & self . ty )
78
85
. finish ( )
79
86
}
0 commit comments