Skip to main content

rust_pop3_client/
pop3_connection.rs

1use std::io::Write;
2use std::error::Error;
3
4use crate::Pop3Stat;
5use crate::Pop3MessageInfo;
6use crate::Pop3MessageUidInfo;
7
8pub trait Pop3Connection {
9    
10    /// Authenticate a POP3 session using username and password.
11    ///
12    /// This is usually the first set of commands after a POP3 session
13    /// is established.
14    ///
15    /// # Arguments
16    ///
17    /// * `user`     - Name of the user, typically it's e-mail address.
18    /// * `password` - Password of the user. 
19    fn login(&mut self, user: &str, password: &str) -> Result<(), Box<dyn Error>>;
20
21    /// Returns maildrop statistics.
22    fn stat(&mut self) -> Result<Pop3Stat, Box<dyn Error>>;
23
24    /// Returns id and size of each message.
25    fn list(&mut self) -> Result<Vec<Pop3MessageInfo>, Box<dyn Error>>;
26
27    /// Returns the size of a given message.
28    ///
29    /// # Arguments
30    ///
31    /// * `message_id` - id of the message to query
32    fn get_message_size(&mut self, message_id: u32) -> Result<u32, Box<dyn Error>>;
33
34    /// Downloads a given message.
35    ///
36    /// # Arguments
37    ///
38    /// * `message_id` - id of the message to download
39    /// * `writer`     - writer to store message
40    fn retrieve(&mut self, message_id: u32, writer: &mut dyn Write) -> Result<(), Box<dyn Error>>;
41
42    /// Deletes a given message.
43    ///
44    /// # Arguments
45    ///
46    /// * `message_id` - id of the message to download
47    fn delete(&mut self, message_id: u32) -> Result<(), Box<dyn Error>>;
48
49    /// Unmark any messages marked as delete.
50    fn reset(&mut self) -> Result<(), Box<dyn Error>>;
51
52    /// Returns the message header an a given number of lines from the message.
53    ///
54    /// # Arguments
55    ///
56    /// * `message_id` - id of the message
57    /// * `line_count` - count of lines to return from the message body
58    fn top(&mut self, message_id: u32, line_count: u32) -> Result<String, Box<dyn Error>>;
59
60    /// Returns the unique ids of all messages.
61    fn list_unique_ids(&mut self) -> Result<Vec<Pop3MessageUidInfo>, Box<dyn Error>>;
62
63    /// Returns the unique id of a given message.
64    ///
65    /// # Arguments
66    ///
67    /// * `message_id` - id of the message
68    fn get_unique_id(&mut self, message_id :u32) -> Result<String, Box<dyn Error>>;
69}