@@ -1096,6 +1096,26 @@ impl<T: Read + Write> Session<T> {
1096
1096
mailbox : S ,
1097
1097
content : B ,
1098
1098
flags : & [ Flag < ' _ > ] ,
1099
+ ) -> Result < ( ) > {
1100
+ self . append_with_flags_and_date ( mailbox, content, flags, None )
1101
+ }
1102
+
1103
+ /// The [`APPEND` command](https://tools.ietf.org/html/rfc3501#section-6.3.11) can take
1104
+ /// an optional FLAGS parameter to set the flags on the new message.
1105
+ ///
1106
+ /// > If a flag parenthesized list is specified, the flags SHOULD be set
1107
+ /// > in the resulting message; otherwise, the flag list of the
1108
+ /// > resulting message is set to empty by default. In either case, the
1109
+ /// > Recent flag is also set.
1110
+ ///
1111
+ /// The [`\Recent` flag](https://tools.ietf.org/html/rfc3501#section-2.3.2) is not
1112
+ /// allowed as an argument to `APPEND` and will be filtered out if present in `flags`.
1113
+ pub fn append_with_flags_and_date < S : AsRef < str > , B : AsRef < [ u8 ] > > (
1114
+ & mut self ,
1115
+ mailbox : S ,
1116
+ content : B ,
1117
+ flags : & [ Flag < ' _ > ] ,
1118
+ date : Option < chrono:: NaiveDateTime > ,
1099
1119
) -> Result < ( ) > {
1100
1120
let content = content. as_ref ( ) ;
1101
1121
let flagstr = flags
@@ -1105,10 +1125,22 @@ impl<T: Read + Write> Session<T> {
1105
1125
. collect :: < Vec < String > > ( )
1106
1126
. join ( " " ) ;
1107
1127
1128
+ // date-time = DQUOTE date-day-fixed "-" date-month "-" date-year SP time SP zone DQUOTE
1129
+ // date-day-fixed = (SP DIGIT) / 2DIGIT
1130
+ // date-month = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" / "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec"
1131
+ // date-year = 4DIGIT
1132
+ // time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
1133
+ // zone = ("+" / "-") 4DIGIT
1134
+ let datestr = match date {
1135
+ Some ( date) => format ! ( " \" {} +0000\" " , date. format( "%d-%h-%Y %T" ) ) ,
1136
+ None => "" . to_string ( ) ,
1137
+ } ;
1138
+
1108
1139
self . run_command ( & format ! (
1109
- "APPEND \" {}\" ({}) {{{}}}" ,
1140
+ "APPEND \" {}\" ({}){} {{{}}}" ,
1110
1141
mailbox. as_ref( ) ,
1111
1142
flagstr,
1143
+ datestr,
1112
1144
content. len( )
1113
1145
) ) ?;
1114
1146
let mut v = Vec :: new ( ) ;
0 commit comments