Crate mailpot

source ·
Expand description

Mailing list manager library.

Data is stored in a sqlite3 database. You can inspect the schema in SCHEMA.

Usage

mailpot can be used with the CLI tool in mailpot-cli, and/or in the web interface of the mailpot-web crate.

You can also directly use this crate as a library.

Example

use mailpot::{models::*, Configuration, Connection, SendMail};

let db = Connection::open_or_create_db(config)?.trusted();

// Create a new mailing list
let list_pk = db
    .create_list(MailingList {
        pk: 0,
        name: "foobar chat".into(),
        id: "foo-chat".into(),
        address: "foo-chat@example.com".into(),
        topics: vec![],
        description: None,
        archive_url: None,
    })?
    .pk;

db.set_list_post_policy(PostPolicy {
    pk: 0,
    list: list_pk,
    announce_only: false,
    subscription_only: true,
    approval_needed: false,
    open: false,
    custom: false,
})?;

// Drop privileges; we can only process new e-mail and modify subscriptions from now on.
let mut db = db.untrusted();

assert_eq!(db.list_subscriptions(list_pk)?.len(), 0);
assert_eq!(db.list_posts(list_pk, None)?.len(), 0);

// Process a subscription request e-mail
let subscribe_bytes = b"From: Name <user@example.com>
To: <foo-chat+subscribe@example.com>
Subject: subscribe
Date: Thu, 29 Oct 2020 13:58:16 +0000
Message-ID: <1@example.com>

";
let envelope = melib::Envelope::from_bytes(subscribe_bytes, None)?;
db.post(&envelope, subscribe_bytes, /* dry_run */ false)?;

assert_eq!(db.list_subscriptions(list_pk)?.len(), 1);
assert_eq!(db.list_posts(list_pk, None)?.len(), 0);

// Process a post
let post_bytes = b"From: Name <user@example.com>
To: <foo-chat@example.com>
Subject: my first post
Date: Thu, 29 Oct 2020 14:01:09 +0000
Message-ID: <2@example.com>

Hello
";
let envelope = melib::Envelope::from_bytes(post_bytes, None).expect("Could not parse message");
db.post(&envelope, post_bytes, /* dry_run */ false)?;

assert_eq!(db.list_subscriptions(list_pk)?.len(), 1);
assert_eq!(db.list_posts(list_pk, None)?.len(), 1);

Re-exports

Modules

Structs

Enums

Constants

Traits

  • This trait is implemented on all the errors generated by the error_chain macro.
  • Provides the context method for Result.
  • Additional methods for Result, for easy interaction with this crate.
  • Trait for stripping carets (‘<’,‘>’) from Message IDs.

Functions

Type Definitions