Struct mailpot::Connection

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

A connection to a mailpot database.

Fields§

§connection: DbConnection

The rusqlite connection handle.

§conf: Configuration

Implementations§

source§

impl Connection

source

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

Fetch all.

source

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

Fetch a named template.

source

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

Insert a named template.

source

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

Remove a named template.

source§

impl Connection

source

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

Insert a received email into a queue.

source

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

Fetch all queue entries.

source

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

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>

Insert a received email into the error queue.

source

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

Fetch all error queue entries.

source

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

Delete error queue entries.

source§

impl Connection

source

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

Insert a mailing list post into the database.

source

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

Process a new mailing list post.

source

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

source

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

Process a new mailing list request.

source

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

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>>>

Find a post by its Message-ID email header.

source

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

Helper function to send a template reply.

source§

impl Connection

source

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

Fetch all subscriptions of a mailing list.

source

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

Fetch mailing list subscription.

source

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

Fetch mailing list subscription by their address.

source

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

Add subscription to mailing list.

source

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

Create subscription candidate.

source

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

Accept subscription candidate.

source

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

Remove a subscription by their address.

source

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

Update a mailing list subscription.

source

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

Fetch account by pk.

source

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

Fetch account by address.

source

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

Fetch all subscriptions of an account by primary key.

source

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

Fetch all accounts.

source

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

Add account.

source

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

Remove an account by their address.

source

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

Update an account.

source§

impl Connection

source

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

Fetch the post policy of a mailing list.

source

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

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 remove_list_post_policy_panic()



let db = Connection::open_or_create_db(config).unwrap().trusted();
db.remove_list_post_policy(1, 1).unwrap();
source

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

Set the unique post policy for a list.

source§

impl Connection

source

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

Fetch the subscription policy of a mailing list.

source

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

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 remove_list_subscription_policy_panic()



let db = Connection::open_or_create_db(config).unwrap().trusted();
db.remove_list_post_policy(1, 1).unwrap();
source

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

Set the unique post policy for a list.

source§

impl Connection

source

pub fn open_db(conf: Configuration) -> Result<Self>

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) -> Self

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

source

pub fn untrusted(self) -> Self

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<Self>

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<()>

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

source

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

Returns a vector of existing mailing lists.

source

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

Fetch a mailing list by primary key.

source

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

Fetch a mailing list by id.

source

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

Create a new list.

source

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

Fetch all posts of a mailing list.

source

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

Fetch the owners of a mailing list.

source

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

Remove an owner of a mailing list.

source

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

Add an owner of a mailing list.

source

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

Update a mailing list.

source

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

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>> + Send + 'static>>>

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 ) -> Result<()>

Submit queue items from values to their recipients.

Trait Implementations§

source§

impl Debug for Connection

source§

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

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.