|
|
| version 1.78, 2002/08/13 15:55:41 | version 1.87, 2002/12/26 14:01:46 |
|---|---|
| Line 96 static const String& attach_hash_to_stri | Line 96 static const String& attach_hash_to_stri |
| struct Mail_info { | struct Mail_info { |
| Charset *charset; const char *content_charset_name; | Charset *charset; const char *content_charset_name; |
| String *header; | String *header; |
| const String **from, **to; | const String **from; |
| String **to; | |
| const String *errors_to; | const String *errors_to; |
| bool mime_version_specified; | |
| }; | }; |
| #endif | #endif |
| const String& extractEmail(const String& string); | String& extractEmails(const String& string); |
| static void add_header_attribute(const Hash::Key& raw_element_name, Hash::Val *aelement_value, | static void add_header_attribute(const Hash::Key& raw_element_name, Hash::Val *aelement_value, |
| void *info) { | void *info) { |
| Value& element_value=*static_cast<Value *>(aelement_value); | Value& element_value=*static_cast<Value *>(aelement_value); |
| Line 115 static void add_header_attribute(const H | Line 117 static void add_header_attribute(const H |
| // fetch from & to from header for SMTP | // fetch from & to from header for SMTP |
| if(mi.from && low_element_name=="from") | if(mi.from && low_element_name=="from") |
| *mi.from=&extractEmail(element_value.as_string()); | *mi.from=&extractEmails(element_value.as_string()); |
| if(mi.to && low_element_name=="to") | if(mi.to && low_element_name=="to") |
| *mi.to=&extractEmail(element_value.as_string()); | *mi.to=&extractEmails(element_value.as_string()); |
| if(low_element_name=="errors-to") | if(low_element_name=="errors-to") |
| mi.errors_to=&extractEmail(element_value.as_string()); | mi.errors_to=&extractEmails(element_value.as_string()); |
| if(low_element_name=="mime-version") | |
| mi.mime_version_specified=true; | |
| // append header line | // append header line |
| *mi.header << | *mi.header << |
| low_element_name << ":" << | low_element_name << ":" << |
| attributed_meaning_to_string(element_value, String::UL_MAIL_HEADER). | attributed_meaning_to_string(element_value, String::UL_MAIL_HEADER, true). |
| cstr(String::UL_UNSPECIFIED, 0, mi.charset, mi.content_charset_name) << | cstr(String::UL_UNSPECIFIED, 0, mi.charset, mi.content_charset_name) << |
| "\n"; | "\n"; |
| } | } |
| Line 168 static int sort_cmp_string_double_value( | Line 172 static int sort_cmp_string_double_value( |
| } | } |
| static const String& message_hash_to_string(Request& r, const String& method_name, | static const String& message_hash_to_string(Request& r, const String& method_name, |
| Hash& message_hash, int level, | Hash& message_hash, int level, |
| const String **from, const String **to) { | const String **from, String **to) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| // prepare header: 'hash' without "body" | // prepare header: 'hash' without "body" |
| Line 198 static const String& message_hash_to_str | Line 202 static const String& message_hash_to_str |
| message_hash.for_each(add_header_attribute, &mail_info); | message_hash.for_each(add_header_attribute, &mail_info); |
| if(!mail_info.errors_to) | if(!mail_info.errors_to) |
| result << "errors-to: postmaster\n"; // errors-to: default | result << "errors-to: postmaster\n"; // errors-to: default |
| if(!mail_info.mime_version_specified) | |
| result << "MIME-Version: 1.0\n"; // MIME-Version: default | |
| if(Value *body_element=static_cast<Value *>(message_hash.get(*body_name))) { | if(Value *body_element=static_cast<Value *>(message_hash.get(*body_name))) { |
| if(Hash *body_hash=body_element->get_hash(&method_name)) { | if(Hash *body_hash=body_element->get_hash(&method_name)) { |
| Line 275 static void sendmail(Request& r, const S | Line 281 static void sendmail(Request& r, const S |
| Hash *mail_conf=static_cast<Hash *>(r.classes_conf.get(mail_base_class->name())); | Hash *mail_conf=static_cast<Hash *>(r.classes_conf.get(mail_base_class->name())); |
| const char *exception_type="email.format"; | const char *exception_type="email.format"; |
| if(!from) | if(!from) // we use in sendmail -f {from} && SMTP MAIL from: {from} |
| throw Exception(exception_type, | throw Exception(exception_type, |
| &method_name, | &method_name, |
| "parameter does not specify 'from' header field"); | "parameter does not specify 'from' header field"); |
| if(!to) | |
| #ifdef _MSC_VER | |
| if(!to) // we use only in SMTP RCPT to: {to} | |
| throw Exception(exception_type, | throw Exception(exception_type, |
| &method_name, | &method_name, |
| "parameter does not specify 'to' header field"); | "parameter does not specify 'to' header field"); |
| #ifdef _MSC_VER | |
| SMTP& smtp=*new(pool) SMTP(pool, method_name); | SMTP& smtp=*new(pool) SMTP(pool, method_name); |
| Value *server_port; | Value *server_port; |
| Line 307 static void sendmail(Request& r, const S | Line 314 static void sendmail(Request& r, const S |
| // $MAIN:MAIL.sendmail["/usr/lib/sendmail -t -i -f postmaster"] default | // $MAIN:MAIL.sendmail["/usr/lib/sendmail -t -i -f postmaster"] default |
| const String *sendmail_command; | const String *sendmail_command; |
| #ifdef PA_FORCED_SENDMAIL | |
| sendmail_command=new(pool) String(pool, PA_FORCED_SENDMAIL); | |
| #else | |
| const char *sendmailkey_cstr="sendmail"; | const char *sendmailkey_cstr="sendmail"; |
| if(mail_conf) { | if(mail_conf) { |
| #ifdef PA_FORCED_SENDMAIL | |
| throw Exception("parser.runtime", | |
| &method_name, | |
| "Parser was configured with --with-sendmail="PA_FORCED_SENDMAIL | |
| " key, to change sendmail you should reconfigure and recompie it"); | |
| #else | |
| if(Value *sendmail_value=static_cast<Value *>(mail_conf->get(String(pool, sendmailkey_cstr)))) | if(Value *sendmail_value=static_cast<Value *>(mail_conf->get(String(pool, sendmailkey_cstr)))) |
| sendmail_command=&sendmail_value->as_string(); | sendmail_command=&sendmail_value->as_string(); |
| else | else |
| Line 319 static void sendmail(Request& r, const S | Line 329 static void sendmail(Request& r, const S |
| &method_name, | &method_name, |
| "$"MAIN_CLASS_NAME":"MAIL_NAME".%s not defined", | "$"MAIN_CLASS_NAME":"MAIL_NAME".%s not defined", |
| sendmailkey_cstr); | sendmailkey_cstr); |
| #endif | |
| } else { | } else { |
| #ifdef PA_FORCED_SENDMAIL | |
| sendmail_command=new(pool) String(pool, PA_FORCED_SENDMAIL); | |
| #else | |
| String *test=new(pool) String(pool, "/usr/sbin/sendmail"); | String *test=new(pool) String(pool, "/usr/sbin/sendmail"); |
| if(!file_executable(*test)) | if(!file_executable(*test)) |
| test=new(pool) String(pool, "/usr/lib/sendmail"); | test=new(pool) String(pool, "/usr/lib/sendmail"); |
| test->APPEND_CONST(" -t -i -f postmaster"); | test->APPEND_CONST(" -t -i -f postmaster"); |
| sendmail_command=test; | sendmail_command=test; |
| } | |
| #endif | #endif |
| } | |
| // we know sendmail_command here, should replace "postmaster" with "$from" from message | // we know sendmail_command here, should replace "postmaster" with "$from" from message |
| int at_postmaster=sendmail_command->pos("postmaster"); | int at_postmaster=sendmail_command->pos("postmaster"); |
| Line 397 static void _send(Request& r, const Stri | Line 411 static void _send(Request& r, const Stri |
| &method_name, | &method_name, |
| "message must be hash"); | "message must be hash"); |
| const String *from, *to; | const String *from=0; |
| String *to=0; | |
| String **to_param= | |
| #ifdef _MSC_VER | |
| &to | |
| #else | |
| 0 | |
| #endif | |
| ; | |
| const String& message=hash->get(*body_name)/*old format*/? | const String& message=hash->get(*body_name)/*old format*/? |
| message_hash_to_string(r, method_name, *hash, 0, &from, &to) : // old | message_hash_to_string(r, method_name, *hash, 0, &from, to_param) : // old |
| static_cast<VMail *>(r.self)->message_hash_to_string(r, &method_name, hash, 0, &from, &to); // new | static_cast<VMail *>(r.get_self())->message_hash_to_string(r, &method_name, hash, 0, &from, to_param); // new |
| //r.write_pass_lang(message); | //r.write_pass_lang(message); |
| sendmail(r, method_name, message, from, to); | sendmail(r, method_name, message, from, to); |
| Line 419 void MMail::configure_user(Request& r) { | Line 441 void MMail::configure_user(Request& r) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| // $MAIN:MAIL[$SMTP[mail.design.ru]] | // $MAIN:MAIL[$SMTP[mail.design.ru]] |
| if(Value *mail_element=r.main_class->get_element(mail_name, r.main_class, false)) | if(Value *mail_element=r.main_class.get_element(mail_name, r.main_class, false)) |
| if(Hash *mail_conf=mail_element->get_hash(0)) | if(Hash *mail_conf=mail_element->get_hash(0)) |
| r.classes_conf.put(name(), mail_conf); | r.classes_conf.put(name(), mail_conf); |
| else | else |