Struct mailpot::Template

source ·
pub struct Template {
    pub pk: i64,
    pub name: String,
    pub list: Option<i64>,
    pub subject: Option<String>,
    pub headers_json: Option<Value>,
    pub body: String,
}
Expand description

A named template.

Fields§

§pk: i64

Database primary key.

§name: String

Name.

§list: Option<i64>

Associated list foreign key, optional.

§subject: Option<String>

Subject template.

§headers_json: Option<Value>

Extra headers template.

§body: String

Body template.

Implementations§

source§

impl Template

source

pub const GENERIC_HELP: &str = "generic-help"

Template name for generic list help e-mail.

source

pub const GENERIC_FAILURE: &str = "generic-failure"

Template name for generic failure e-mail.

source

pub const GENERIC_SUCCESS: &str = "generic-success"

Template name for generic success e-mail.

source

pub const SUBSCRIPTION_CONFIRMATION: &str = "subscription-confirmation"

Template name for subscription confirmation e-mail.

source

pub const UNSUBSCRIPTION_CONFIRMATION: &str = "unsubscription-confirmation"

Template name for unsubscription confirmation e-mail.

source

pub const SUBSCRIPTION_REQUEST_NOTICE_OWNER: &str = "subscription-notice-owner"

Template name for subscription request notice e-mail (for list owners).

source

pub const SUBSCRIPTION_REQUEST_CANDIDATE_ACCEPT: &str = "subscription-notice-candidate-accept"

Template name for subscription request acceptance e-mail (for the candidates).

source

pub const ADMIN_NOTICE: &str = "admin-notice"

Template name for admin notices.

source

pub fn render(&self, context: Value) -> Result<Draft>

Render a message body from a saved named template.

Examples found in repository?
core/src/posts.rs (line 744)
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
    pub fn send_reply_with_list_template<'ctx, F: Fn() -> Template>(
        &self,
        render_context: TemplateRenderContext<'ctx, F>,
        recipients: impl Iterator<Item = Cow<'ctx, melib::Address>>,
    ) -> Result<()> {
        let TemplateRenderContext {
            template,
            default_fn,
            list,
            context,
            queue,
            comment,
        } = render_context;

        let post_policy = self.list_post_policy(list.pk)?;
        let subscription_policy = self.list_subscription_policy(list.pk)?;

        let templ = self
            .fetch_template(template, Some(list.pk))?
            .map(DbVal::into_inner)
            .or_else(|| default_fn.map(|f| f()))
            .ok_or_else(|| -> crate::Error {
                format!("Template with name {template:?} was not found.").into()
            })?;

        let mut draft = templ.render(context)?;
        draft.headers.insert(
            melib::HeaderName::new_unchecked("From"),
            list.request_subaddr(),
        );
        for addr in recipients {
            let mut draft = draft.clone();
            draft
                .headers
                .insert(melib::HeaderName::new_unchecked("To"), addr.to_string());
            list.insert_headers(
                &mut draft,
                post_policy.as_deref(),
                subscription_policy.as_deref(),
            );
            self.insert_to_queue(QueueEntry::new(
                queue,
                Some(list.pk),
                None,
                draft.finalise()?.as_bytes(),
                Some(comment.to_string()),
            )?)?;
        }
        Ok(())
    }
source

pub fn default_generic_failure() -> Self

Template name for generic failure e-mail.

source

pub fn default_generic_success() -> Self

Create a plain template for generic success e-mails.

source

pub fn default_subscription_confirmation() -> Self

Create a plain template for subscription confirmation.

source

pub fn default_unsubscription_confirmation() -> Self

Create a plain template for unsubscription confirmations.

source

pub fn default_admin_notice() -> Self

Create a plain template for admin notices.

source

pub fn default_subscription_request_owner() -> Self

Create a plain template for subscription requests for list owners.

source

pub fn default_subscription_request_candidate_accept() -> Self

Create a plain template for subscription requests for candidates.

source

pub fn default_generic_help() -> Self

Create a plain template for generic list help replies.

Trait Implementations§

source§

impl Clone for Template

source§

fn clone(&self) -> Template

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Template

source§

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

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

impl<'de> Deserialize<'de> for Template

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Template

source§

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

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

impl PartialEq<Template> for Template

source§

fn eq(&self, other: &Template) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Template

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Template

source§

impl StructuralEq for Template

source§

impl StructuralPartialEq for Template

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
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.
source§

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

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,