Skip to content

Commit a1242a8

Browse files
committed
feat: allow setting sent date on APPEND
References jonhoo#60
1 parent 8be583a commit a1242a8

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/client.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,26 @@ impl<T: Read + Write> Session<T> {
10961096
mailbox: S,
10971097
content: B,
10981098
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>,
10991119
) -> Result<()> {
11001120
let content = content.as_ref();
11011121
let flagstr = flags
@@ -1105,10 +1125,22 @@ impl<T: Read + Write> Session<T> {
11051125
.collect::<Vec<String>>()
11061126
.join(" ");
11071127

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+
11081139
self.run_command(&format!(
1109-
"APPEND \"{}\" ({}) {{{}}}",
1140+
"APPEND \"{}\" ({}){} {{{}}}",
11101141
mailbox.as_ref(),
11111142
flagstr,
1143+
datestr,
11121144
content.len()
11131145
))?;
11141146
let mut v = Vec::new();

0 commit comments

Comments
 (0)