Struct mpot::Connection

source ·
pub struct Connection {
    pub connection: Connection,
    conf: Configuration,
}
Expand description

A connection to a mailpot database.

Fields§

§connection: Connection

The rusqlite connection handle.

§conf: Configuration

Implementations§

source§

impl Connection

source

pub fn fetch_templates(&self) -> Result<Vec<DbVal<Template>, Global>, Error>

Fetch all.

source

pub fn fetch_template( &self, template: &str, list_pk: Option<i64> ) -> Result<Option<DbVal<Template>>, Error>

Fetch a named template.

source

pub fn add_template(&self, template: Template) -> Result<DbVal<Template>, Error>

Insert a named template.

source

pub fn remove_template( &self, template: &str, list_pk: Option<i64> ) -> Result<Template, Error>

Remove a named template.

source§

impl Connection

source

pub fn insert_to_queue( &self, entry: QueueEntry ) -> Result<DbVal<QueueEntry>, Error>

Insert a received email into a queue.

source

pub fn queue( &self, queue: Queue ) -> Result<Vec<DbVal<QueueEntry>, Global>, Error>

Fetch all queue entries.

source

pub fn delete_from_queue( &mut self, queue: Queue, index: Vec<i64, Global> ) -> Result<Vec<QueueEntry, Global>, Error>

Delete queue entries returning the deleted values.

source§

impl Connection

source

pub fn insert_to_error_queue( &self, list_pk: Option<i64>, env: &Envelope, raw: &[u8], reason: String ) -> Result<i64, Error>

Insert a received email into the error queue.

source

pub fn error_queue(&self) -> Result<Vec<DbVal<Value>, Global>, Error>

Fetch all error queue entries.

source

pub fn delete_from_error_queue( &mut self, index: Vec<i64, Global> ) -> Result<(), Error>

Delete error queue entries.

source§

impl Connection

source

pub fn insert_post( &self, list_pk: i64, message: &[u8], env: &Envelope ) -> Result<i64, Error>

Insert a mailing list post into the database.

source

pub fn post( &mut self, env: &Envelope, raw: &[u8], _dry_run: bool ) -> Result<(), Error>

Process a new mailing list post.

source

pub fn request( &mut self, list: &DbVal<MailingList>, request: ListRequest, env: &Envelope, raw: &[u8] ) -> Result<(), Error>

Process a new mailing list request.

source

pub fn months(&self, list_pk: i64) -> Result<Vec<String, Global>, Error>

Fetch all year and month values for which at least one post exists in yyyy-mm format.

source

pub fn list_post_by_message_id( &self, list_pk: i64, message_id: &str ) -> Result<Option<DbVal<Post>>, Error>

Find a post by its Message-ID email header.

source

pub fn send_reply_with_list_template<'ctx, F>( &self, render_context: TemplateRenderContext<'ctx, F>, recipients: impl Iterator<Item = Cow<'ctx, Address>> ) -> Result<(), Error>where F: Fn() -> Template,

Helper function to send a template reply.

source§

impl Connection

source

pub fn list_subscriptions( &self, pk: i64 ) -> Result<Vec<DbVal<ListSubscription>, Global>, Error>

Fetch all subscriptions of a mailing list.

source

pub fn list_subscription( &self, list_pk: i64, pk: i64 ) -> Result<DbVal<ListSubscription>, Error>

Fetch mailing list subscription.

source

pub fn list_subscription_by_address( &self, list_pk: i64, address: &str ) -> Result<DbVal<ListSubscription>, Error>

Fetch mailing list subscription by their address.

source

pub fn add_subscription( &self, list_pk: i64, new_val: ListSubscription ) -> Result<DbVal<ListSubscription>, Error>

Add subscription to mailing list.

source

pub fn add_candidate_subscription( &mut self, list_pk: i64, new_val: ListSubscription ) -> Result<DbVal<ListCandidateSubscription>, Error>

Create subscription candidate.

source

pub fn accept_candidate_subscription( &mut self, pk: i64 ) -> Result<DbVal<ListSubscription>, Error>

Accept subscription candidate.

source

pub fn remove_subscription( &self, list_pk: i64, address: &str ) -> Result<(), Error>

Remove a subscription by their address.

source

pub fn update_subscription( &mut self, change_set: ListSubscriptionChangeset ) -> Result<(), Error>

Update a mailing list subscription.

source

pub fn account(&self, pk: i64) -> Result<Option<DbVal<Account>>, Error>

Fetch account by pk.

source

pub fn account_by_address( &self, address: &str ) -> Result<Option<DbVal<Account>>, Error>

Fetch account by address.

source

pub fn account_subscriptions( &self, pk: i64 ) -> Result<Vec<DbVal<ListSubscription>, Global>, Error>

Fetch all subscriptions of an account by primary key.

source

pub fn accounts(&self) -> Result<Vec<DbVal<Account>, Global>, Error>

Fetch all accounts.

source

pub fn add_account(&self, new_val: Account) -> Result<DbVal<Account>, Error>

Add account.

source

pub fn remove_account(&self, address: &str) -> Result<(), Error>

Remove an account by their address.

source

pub fn update_account( &mut self, change_set: AccountChangeset ) -> Result<(), Error>

Update an account.

source§

impl Connection

source

pub fn list_post_policy( &self, pk: i64 ) -> Result<Option<DbVal<PostPolicy>>, Error>

Fetch the post policy of a mailing list.

source

pub fn remove_list_post_policy( &self, list_pk: i64, policy_pk: i64 ) -> Result<(), Error>

Remove an existing list policy.



let db = Connection::open_or_create_db(config).unwrap().trusted();
let list_pk = db
    .create_list(MailingList {
        pk: 0,
        name: "foobar chat".into(),
        id: "foo-chat".into(),
        address: "foo-chat@example.com".into(),
        description: None,
        archive_url: None,
    })
    .unwrap()
    .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,
})
.unwrap();
db.remove_list_post_policy(1, 1).unwrap();
source

pub fn set_list_post_policy( &self, policy: PostPolicy ) -> Result<DbVal<PostPolicy>, Error>

Set the unique post policy for a list.

source§

impl Connection

source

pub fn list_subscription_policy( &self, pk: i64 ) -> Result<Option<DbVal<SubscriptionPolicy>>, Error>

Fetch the subscription policy of a mailing list.

source

pub fn remove_list_subscription_policy( &self, list_pk: i64, policy_pk: i64 ) -> Result<(), Error>

Remove an existing list policy.



let db = Connection::open_or_create_db(config).unwrap().trusted();
let list_pk = db
    .create_list(MailingList {
        pk: 0,
        name: "foobar chat".into(),
        id: "foo-chat".into(),
        address: "foo-chat@example.com".into(),
        description: None,
        archive_url: None,
    })
    .unwrap()
    .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,
})
.unwrap();
db.remove_list_post_policy(1, 1).unwrap();
source

pub fn set_list_subscription_policy( &self, policy: SubscriptionPolicy ) -> Result<DbVal<SubscriptionPolicy>, Error>

Set the unique post policy for a list.

source§

impl Connection

source

pub fn open_db(conf: Configuration) -> Result<Connection, Error>

Creates a new database connection.

Connection supports a limited subset of operations by default (see Connection::untrusted). Use Connection::trusted to remove these limits.

source

pub fn trusted(self) -> Connection

Removes operational limits from this connection. (see Connection::untrusted)

source

pub fn untrusted(self) -> Connection

Sets operational limits for this connection.

  • Allow INSERT, DELETE only for “queue”, “candidate_subscription”, “subscription”.
  • Allow UPDATE only for “subscription” user facing settings.
  • Allow INSERT only for “post”.
  • Allow read access to all tables.
  • Allow SELECT, TRANSACTION, SAVEPOINT, and the strftime function.
  • Deny everything else.
source

pub fn open_or_create_db(conf: Configuration) -> Result<Connection, Error>

Create a database if it doesn’t exist and then open it.

source

pub fn conf(&self) -> &Configuration

Returns a connection’s configuration.

source

pub fn load_archives(&self) -> Result<(), Error>

Loads archive databases from Configuration::data_path, if any.

source

pub fn lists(&self) -> Result<Vec<DbVal<MailingList>, Global>, Error>

Returns a vector of existing mailing lists.

source

pub fn list(&self, pk: i64) -> Result<Option<DbVal<MailingList>>, Error>

Fetch a mailing list by primary key.

source

pub fn list_by_id<S>(&self, id: S) -> Result<Option<DbVal<MailingList>>, Error>where S: AsRef<str>,

Fetch a mailing list by id.

source

pub fn create_list( &self, new_val: MailingList ) -> Result<DbVal<MailingList>, Error>

Create a new list.

source

pub fn list_posts( &self, list_pk: i64, _date_range: Option<(String, String)> ) -> Result<Vec<DbVal<Post>, Global>, Error>

Fetch all posts of a mailing list.

source

pub fn list_owners( &self, pk: i64 ) -> Result<Vec<DbVal<ListOwner>, Global>, Error>

Fetch the owners of a mailing list.

source

pub fn remove_list_owner(&self, list_pk: i64, owner_pk: i64) -> Result<(), Error>

Remove an owner of a mailing list.

source

pub fn add_list_owner( &self, list_owner: ListOwner ) -> Result<DbVal<ListOwner>, Error>

Add an owner of a mailing list.

source

pub fn update_list( &mut self, change_set: MailingListChangeset ) -> Result<(), Error>

Update a mailing list.

source

pub fn list_filters( &self, _list: &DbVal<MailingList> ) -> Vec<Box<dyn PostFilter + 'static, Global>, Global>

Return the post filters of a mailing list.

source§

impl Connection

source

pub fn new_smtp_connection( &self ) -> Result<Pin<Box<dyn Future<Output = Result<SmtpConnection, Error>> + Send + 'static, Global>>, Error>

Return an SMTP connection handle if the database connection has one configured.

source

pub async fn submit( smtp_connection: &mut SmtpConnection, message: &QueueEntry, dry_run: bool ) -> impl Future<Output = Result<(), Error>>

Submit queue items from values to their recipients.

Trait Implementations§

source§

impl Debug for Connection

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Drop for Connection

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.