#internal #resources #context #header #bodies #builder

mail-core-ng

[mail/core] 为 mail crate 提供了 Mail 类型(包括多部分 MIME 主体、构建器和资源类型)

1 个不稳定版本

使用旧的 Rust 2015

0.6.3 2023年8月7日

#178电子邮件

MIT/Apache

140KB
2.5K SLoC

mail-core

mail crate 提供核心邮件类型 Mail


此 crate 提供了名为 mail 的类型以及创建它的方法。它还提供了构建器上下文接口和 Resource 类型,用于表示邮件主体。特别是附件或嵌入图像。

示例

extern crate futures;
// Note that the `mail` crate provides a facade re-exporting
// all relevant parts.
extern crate mail_core;
extern crate mail_internals;
#[macro_use]
extern crate mail_headers;

use std::str;
use futures::Future;

use mail_internals::MailType;

// In the facade this is the `headers` module.
use mail_headers::{
    headers::*,
    header_components::Domain
};

// In the facade this types (and the default_impl module)
// are also exposed at top level
use mail_core::{
    Mail,
    default_impl::simple_context,
    error::MailError
};

fn print_some_mail() -> Result<(), MailError> {
    // Domain will implement `from_str` in the future,
    // currently it doesn't have a validator/parser.
    // So this will become `"example.com".parse()`
    let domain = Domain::from_unchecked("example.com".to_owned());
    // Normally you create this _once per application_.
    let ctx = simple_context::new(domain, "xqi93".parse().expect("we know it's ascii"))
        .expect("this is basically: failed to get cwd from env");

    let mut mail = Mail::plain_text("Hy there! 😁");
    mail.insert_headers(headers! {
        _From: [("I'm Awesome 😁", "[email protected]")],
        _To: ["[email protected]"],
        Subject: "Hy there message 😁"
    }?);

    // We don't added any think which needs loading but we could have
    // and all of it would have been loaded concurrent and async.
    let encoded = mail.into_encodable_mail(ctx.clone())
        .wait()?
        .encode_into_bytes(MailType::Ascii)?;

    let mail_str = str::from_utf8(&encoded).unwrap();
    println!("{}", mail_str);
    Ok(())
}

fn main() {
    print_some_mail().unwrap()
}

文档可以在 docs.rs 上查看(一旦发布)。

许可证

根据以下任一许可证授权:

任选其一。

贡献

除非您明确声明,否则任何有意提交以包含在作品中的贡献,根据 Apache-2.0 许可证的定义,应按上述方式双许可,而不附加任何额外的条款或条件。

依赖项

~6MB
~129K SLoC