Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying email content #82

Closed
GreeFine opened this issue Jul 24, 2018 · 2 comments
Closed

Displaying email content #82

GreeFine opened this issue Jul 24, 2018 · 2 comments

Comments

@GreeFine
Copy link

Hello, I used a previous versions of this crate to fetch and get the email content, but with the updated version i don't find anything on how to access the contents of the fetch.

Previously i fetched and got my reponsse like this:

match imap_socket.fetch(&seq, "BODY.PEEK[HEADER.FIELDS (FROM SUBJECT DATE)]") {
    Ok(lines) => {
        println!("{:?}", lines[0]);
        // from = lines[1];
        // subject = lines[2];
        // date = lines[3];
    }
    Err(e) => println!("Error Fetching email {}: {}", x, e),
};

But now even with this and the example you give, I only get a list of flags and some ID/UID
Fetch { message: 348, flags: ["\\Seen"], uid: None, rfc822_header: None, rfc822: None }Mailbox emails number = 538

I have looked in the documentation and found that now fetch return a vector of imap::Fetch, but i am not abble to find anything leading to my fetch content.

Also, i am very new to RUST so i don't really understand all i am doing 😕

@GreeFine GreeFine changed the title Display email content Displaying email content Jul 24, 2018
@jonhoo
Copy link
Collaborator

jonhoo commented Jul 24, 2018

Hi there! Yes, the old version of this crate did not parse the response that comes back from the server, and instead had you parse it out yourself. As of #58, that has changed, but it does mean that there are some attributes that we don't expose just because we haven't though of them :) The BODY field specifically is parsed as of #76 (through Fetch::body()), but due to #69, I can't actually publish a new version with that at the moment, so you'll have to add the crate as a git dependency.

Alternatively, you can request RFC822 (instead of BODY.PEEK and such), and then access that through Fetch::rfc822. You can see how I do that in buzz here.

@GreeFine
Copy link
Author

Thank you for the support @jonhoo !
Here is the solution i use with your answer.
Maybe put something alike in the example section might help people like me in the future.

let domain = "imap.gmail.com";
let port = 993;
let socket_addr = (domain, port);
let ssl_connector = TlsConnector::builder().unwrap().build().unwrap(); //Using native-tls = "0.1"
let mut imap_socket = Client::secure_connect(socket_addr, domain, &ssl_connector).unwrap();

imap_socket
    .login("[email protected]", "password")
    .unwrap();

match imap_socket.select("INBOX") {
     Ok(mailbox) => {
         println!("{}", mailbox);
     }
     Err(e) => println!("Error selecting INBOX: {}", e),
};

match imap_socket.fetch("2", "RFC822") {
    Ok(messages) => {
        for message in messages.iter() {
            let lines: Vec<&str> = str::from_utf8(message.rfc822().unwrap())
                .unwrap()
                .split("\n")
                .collect();
            for i in 0..lines.len() {
                println!("Lines[{}] {}", i, lines[i]);
            }
        }
    }
    Err(e) => println!("Error Fetching email 2: {}", e),
};

imap_socket.logout().unwrap();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants