From 649e74aad89bd7c84af27aef4b2e25d9ea655972 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Wed, 27 Sep 2006 13:16:55 +0000 Subject: [PATCH] configurable additional header for the voicemail template. Thanks Christophe Irles git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@86 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/voicemail/README.mail-template | 10 +++++++++- core/AmMail.cpp | 5 +++-- core/AmMail.h | 4 +++- core/AmSmtpClient.cpp | 2 ++ core/EmailTemplate.cpp | 11 +++++++++-- core/EmailTemplate.h | 1 + 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/apps/voicemail/README.mail-template b/apps/voicemail/README.mail-template index 4fb995e1..efec5b8a 100644 --- a/apps/voicemail/README.mail-template +++ b/apps/voicemail/README.mail-template @@ -40,9 +40,17 @@ Email template format: to: from: subject: -[empty line] +[header: ] + +The optional header line adds a freely configurable +header to the mail. For example, the voicemail can be +securely filtered for the header X-Content if the following +is used in the voicemail template: +header: X-Content: Voicemail +This line is optional. + Variables: ---------- diff --git a/core/AmMail.cpp b/core/AmMail.cpp index c72e9136..82f83d63 100644 --- a/core/AmMail.cpp +++ b/core/AmMail.cpp @@ -38,8 +38,9 @@ AmMail::AmMail(const string& _from, const string& _subject, - const string& _to, const string& _body) - : from(_from), subject(_subject), body(_body), + const string& _to, const string& _body, + const string& _header) + : from(_from), subject(_subject), body(_body), header(_header), to(_to), clean_up(0), error_count(0) { } diff --git a/core/AmMail.h b/core/AmMail.h index 6f097e0c..aa61503a 100644 --- a/core/AmMail.h +++ b/core/AmMail.h @@ -80,6 +80,7 @@ public: string subject; string body; string to; + string header; /** Char set */ string charset; @@ -92,7 +93,8 @@ public: int error_count; AmMail(const string& _from, const string& _subject, - const string& _to, const string& _body = ""); + const string& _to, const string& _body = "", + const string& _header = ""); ~AmMail(); }; diff --git a/core/AmSmtpClient.cpp b/core/AmSmtpClient.cpp index 08de8d7f..74cc6335 100644 --- a/core/AmSmtpClient.cpp +++ b/core/AmSmtpClient.cpp @@ -108,6 +108,8 @@ bool AmSmtpClient::send(const AmMail& mail) string rcpt_to = "rcpt to: <" + mail.to + ">"; vector headers; + + if (!mail.header.empty()) headers.push_back(mail.header); headers.push_back("From: " + mail.from); headers.push_back("To: " + mail.to); headers.push_back("Subject: " + mail.subject); diff --git a/core/EmailTemplate.cpp b/core/EmailTemplate.cpp index c58cebff..b4040835 100644 --- a/core/EmailTemplate.cpp +++ b/core/EmailTemplate.cpp @@ -72,6 +72,7 @@ int EmailTemplate::load(const string& filename) #define P_SUBJECT 1 #define P_TO 2 #define P_FROM 3 +#define P_HEADER 4 int EmailTemplate::parse(char* buffer) { @@ -103,6 +104,9 @@ int EmailTemplate::parse(char* buffer) else if(!strncmp(begin,"from",4)){ state = P_FROM; } + else if(!strncmp(begin,"header",4)){ + state = P_HEADER; + } else state = 0; @@ -125,6 +129,9 @@ int EmailTemplate::parse(char* buffer) case P_FROM: from = begin; break; + case P_HEADER: + header = begin; + break; } begin = ++s; } @@ -149,7 +156,6 @@ int EmailTemplate::parse(char* buffer) ERROR("EmailTemplate: invalid template: empty body\n"); return -1; } - return 0; } @@ -227,7 +233,8 @@ AmMail EmailTemplate::getEmail(const EmailTmplDict& dict) const return AmMail(replaceVars(from,dict), replaceVars(subject,dict), replaceVars(to,dict), - replaceVars(body,dict)); + replaceVars(body,dict), + replaceVars(header,dict)); } catch(const string& err){ throw string("EmailTemplate: error in template '" + tmpl_file + "': " + err); diff --git a/core/EmailTemplate.h b/core/EmailTemplate.h index 542f9427..967c47d2 100644 --- a/core/EmailTemplate.h +++ b/core/EmailTemplate.h @@ -46,6 +46,7 @@ class EmailTemplate string to; string from; string body; + string header; int parse(char* buffer); string replaceVars(const string& str,const EmailTmplDict& dict) const;