#gmail #temp-mail #api-wrapper #api-bindings

已删除 gmailnator

用于与 https://gmailnator.com/ 交互的非官方 API 包装器

0.2.1 2020年11月22日
0.2.0 2020年11月15日
0.1.5 2020年10月31日

#15 in #gmail

GPL-3.0-only

24KB
398 代码行

Generic badge Generic badge

请参阅 docs.rs 上的文档,以获取最新的示例。


lib.rs:

此库包含创建 gmailnator 收件箱和读取其中消息的对象。

入门

主要的结构体是 GmailnatorInbox 结构体,一个实例包含与一个电子邮件地址关联的一个收件箱。

这创建了一个新的临时电子邮件地址

use gmailnator::GmailnatorInbox;

let inbox = GmailnatorInbox::new().unwrap();

要获取关联的电子邮件地址

let address:&str = inbox.get_address();

这创建了 n 个地址,必须使用它来创建大量的收件箱。

use gmailnator::GmailnatorInbox;

let n:u32 = 500;
let inboxes:Vec<GmailnatorInbox> = GmailnatorInbox::new_bulk(n).unwrap();

assert_eq!(inboxes.len() as u32, n); 

通过容器结构体 MailMessage 获取向量中的消息并显示它们

use gmailnator::{GmailnatorInbox, MailMessage};
let messages:Vec<MailMessage> = inbox.get_messages_iter().unwrap().collect();

for message in messages {

    let title = message.get_subject();

    let raw_body = message.get_raw_content();
    let decoded_body = message.decode_content().unwrap();

    // raw_body     = &lt;You&gt; Where did you put the &quot;thing&quot; ?
    // decoded_body = <You> Where did you put the "thing" ?

    println!("Title : {}\nBody : {}", title, decoded_body);

}

要搜索特定的消息,请使用 MailMessageIterator

use gmailnator::{GmailnatorInbox, MailMessage, MailMessageIterator};
let mut messages_iter:MailMessageIterator = inbox.get_messages_iter().unwrap();

let find_result = messages_iter.find(|m| m.get_subject() == "Confirm your order");

if let Some(confirmation_message) = find_result {

  //Confirm your order :)

}

依赖项

~9–16MB
~239K SLoC