Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ path = "src/lib.rs"
native-tls = "0.1"
regex = "0.2"
bufstream = "0.1"
chrono = "0.4"

[dev-dependencies]
base64 = "0.7"
45 changes: 42 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::fmt;
use std::net::{TcpStream, ToSocketAddrs};
use native_tls::{TlsConnector, TlsStream};
use std::io::{self, Read, Write};
use std::time::Duration;
use bufstream::BufStream;
use chrono::prelude::*;

use super::mailbox::Mailbox;
use super::authenticator::Authenticator;
Expand Down Expand Up @@ -448,9 +450,46 @@ impl<T: Read + Write> Client<T> {
IdleHandle::new(self)
}

/// The APPEND command adds a mail to a mailbox.
pub fn append(&mut self, folder: &str, content: &[u8]) -> Result<Vec<String>> {
try!(self.run_command(&format!("APPEND \"{}\" {{{}}}", folder, content.len())));
/// The APPEND command adds a mail to a mailbox. If the datetime or flags are unspecified they
/// are not included in the request.
pub fn append<Tz: TimeZone>(
&mut self,
folder: &str,
flags: Option<Vec<String>>,
datetime: Option<DateTime<Tz>>,
content: &[u8],
) -> Result<Vec<String>>
where
Tz::Offset: fmt::Display,
{
// Set up optional flags.
let mut optionals = String::new();
match flags {
None => (),
Some(flags) => {
optionals.push_str(&format!(
"({})",
flags
.iter()
.fold(String::new(), |acc, ref flag| acc + " " + &flag)
.trim()
));
}
}
optionals.push(' ');
match datetime {
None => (),
Some(datetime) => {
optionals.push_str(&format!("\"{}\"", datetime.format("%d-%b-%Y %H:%M:%S %z")))
}
}

try!(self.run_command(&format!(
"APPEND \"{}\" {} {{{}}}",
folder,
optionals,
content.len()
)));
let line = try!(self.readline());
if !line.starts_with(b"+") {
return Err(Error::Append);
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! imap is a IMAP client for Rust.

extern crate bufstream;
extern crate chrono;
extern crate native_tls;
extern crate regex;

Expand Down