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
impl Template
sourcepub const GENERIC_HELP: &str = "generic-help"
pub const GENERIC_HELP: &str = "generic-help"
Template name for generic list help e-mail.
sourcepub const GENERIC_FAILURE: &str = "generic-failure"
pub const GENERIC_FAILURE: &str = "generic-failure"
Template name for generic failure e-mail.
sourcepub const GENERIC_SUCCESS: &str = "generic-success"
pub const GENERIC_SUCCESS: &str = "generic-success"
Template name for generic success e-mail.
sourcepub const SUBSCRIPTION_CONFIRMATION: &str = "subscription-confirmation"
pub const SUBSCRIPTION_CONFIRMATION: &str = "subscription-confirmation"
Template name for subscription confirmation e-mail.
sourcepub const UNSUBSCRIPTION_CONFIRMATION: &str = "unsubscription-confirmation"
pub const UNSUBSCRIPTION_CONFIRMATION: &str = "unsubscription-confirmation"
Template name for unsubscription confirmation e-mail.
sourcepub const SUBSCRIPTION_REQUEST_NOTICE_OWNER: &str = "subscription-notice-owner"
pub const SUBSCRIPTION_REQUEST_NOTICE_OWNER: &str = "subscription-notice-owner"
Template name for subscription request notice e-mail (for list owners).
sourcepub const SUBSCRIPTION_REQUEST_CANDIDATE_ACCEPT: &str = "subscription-notice-candidate-accept"
pub const SUBSCRIPTION_REQUEST_CANDIDATE_ACCEPT: &str = "subscription-notice-candidate-accept"
Template name for subscription request acceptance e-mail (for the candidates).
sourcepub const ADMIN_NOTICE: &str = "admin-notice"
pub const ADMIN_NOTICE: &str = "admin-notice"
Template name for admin notices.
sourcepub fn render(&self, context: Value) -> Result<Draft>
pub fn render(&self, context: Value) -> Result<Draft>
Render a message body from a saved named template.
Examples found in repository?
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(())
}
sourcepub fn default_generic_failure() -> Self
pub fn default_generic_failure() -> Self
Template name for generic failure e-mail.
sourcepub fn default_generic_success() -> Self
pub fn default_generic_success() -> Self
Create a plain template for generic success e-mails.
sourcepub fn default_subscription_confirmation() -> Self
pub fn default_subscription_confirmation() -> Self
Create a plain template for subscription confirmation.
sourcepub fn default_unsubscription_confirmation() -> Self
pub fn default_unsubscription_confirmation() -> Self
Create a plain template for unsubscription confirmations.
sourcepub fn default_admin_notice() -> Self
pub fn default_admin_notice() -> Self
Create a plain template for admin notices.
sourcepub fn default_subscription_request_owner() -> Self
pub fn default_subscription_request_owner() -> Self
Create a plain template for subscription requests for list owners.
sourcepub fn default_subscription_request_candidate_accept() -> Self
pub fn default_subscription_request_candidate_accept() -> Self
Create a plain template for subscription requests for candidates.
sourcepub fn default_generic_help() -> Self
pub fn default_generic_help() -> Self
Create a plain template for generic list help replies.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Template
impl<'de> Deserialize<'de> for Template
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl PartialEq<Template> for Template
impl PartialEq<Template> for Template
impl Eq for Template
impl StructuralEq for Template
impl StructuralPartialEq for Template
Auto Trait Implementations§
impl RefUnwindSafe for Template
impl Send for Template
impl Sync for Template
impl Unpin for Template
impl UnwindSafe for Template
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.