--- parser3/src/classes/mail.C 2002/07/31 14:35:57 1.71 +++ parser3/src/classes/mail.C 2002/12/19 08:34:32 1.85 @@ -3,10 +3,10 @@ Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - - $Id: mail.C,v 1.71 2002/07/31 14:35:57 paf Exp $ */ +static const char* IDENT_MAIL_C="$Date: 2002/12/19 08:34:32 $"; + #include "pa_config_includes.h" #include "pa_common.h" @@ -96,32 +96,39 @@ static const String& attach_hash_to_stri struct Mail_info { Charset *charset; const char *content_charset_name; String *header; - const String **from, **to; + const String **from; + String **to; + const String *errors_to; + bool mime_version_specified; }; #endif -const String& extractEmail(const String& string); -static void add_header_attribute(const Hash::Key& aattribute, Hash::Val *ameaning, +String& extractEmails(const String& string); +static void add_header_attribute(const Hash::Key& raw_element_name, Hash::Val *aelement_value, void *info) { - - Value& lmeaning=*static_cast(ameaning); + Value& element_value=*static_cast(aelement_value); + const String& low_element_name=raw_element_name.change_case(raw_element_name.pool(), String::CC_LOWER); Mail_info& mi=*static_cast(info); // exclude one attribute [body] - if(aattribute==BODY_NAME - || aattribute==CHARSET_NAME) + if(low_element_name==BODY_NAME + || low_element_name==CHARSET_NAME) return; // fetch from & to from header for SMTP - if(mi.from && aattribute=="from") - *mi.from=&extractEmail(lmeaning.as_string()); - if(mi.to && aattribute=="to") - *mi.to=&extractEmail(lmeaning.as_string()); + if(mi.from && low_element_name=="from") + *mi.from=&extractEmails(element_value.as_string()); + if(mi.to && low_element_name=="to") + *mi.to=&extractEmails(element_value.as_string()); + if(low_element_name=="errors-to") + mi.errors_to=&extractEmails(element_value.as_string()); + if(low_element_name=="mime-version") + mi.mime_version_specified=true; // append header line *mi.header << - aattribute << ":" << - attributed_meaning_to_string(lmeaning, String::UL_MAIL_HEADER). + low_element_name << ":" << + attributed_meaning_to_string(element_value, String::UL_MAIL_HEADER, true). cstr(String::UL_UNSPECIFIED, 0, mi.charset, mi.content_charset_name) << "\n"; } @@ -165,7 +172,7 @@ static int sort_cmp_string_double_value( } static const String& message_hash_to_string(Request& r, const String& method_name, Hash& message_hash, int level, - const String **from, const String **to) { + const String **from, String **to) { Pool& pool=r.pool(); // prepare header: 'hash' without "body" @@ -193,6 +200,10 @@ static const String& message_hash_to_str from, to }; message_hash.for_each(add_header_attribute, &mail_info); + if(!mail_info.errors_to) + 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(message_hash.get(*body_name))) { if(Hash *body_hash=body_element->get_hash(&method_name)) { @@ -244,8 +255,8 @@ static const String& message_hash_to_str "\n"; // header|body separator const String& body=body_element->as_string(); - const void *body_ptr=body.cstr(); // body - size_t body_size=body.size(); // body + const char *body_ptr=body.cstr(String::UL_UNSPECIFIED); // body + size_t body_size=strlen(body_ptr); // body const void *mail_ptr; size_t mail_size; Charset::transcode(pool, @@ -266,18 +277,20 @@ static void sendmail(Request& r, const S const String *from, const String *to) { Pool& pool=r.pool(); - char *message_cstr=message.cstr(); + char *message_cstr=message.cstr(String::UL_UNSPECIFIED); Hash *mail_conf=static_cast(r.classes_conf.get(mail_base_class->name())); - if(!from) - throw Exception("parser.runtime", + const char *exception_type="email.format"; + if(!from) // we use in sendmail -f {from} && SMTP MAIL from: {from} + throw Exception(exception_type, &method_name, "parameter does not specify 'from' header field"); - if(!to) - throw Exception("parser.runtime", + +#ifdef _MSC_VER + if(!to) // we use only in SMTP RCPT to: {to} + throw Exception(exception_type, &method_name, "parameter does not specify 'to' header field"); -#ifdef _MSC_VER SMTP& smtp=*new(pool) SMTP(pool, method_name); Value *server_port; @@ -344,7 +357,7 @@ static void sendmail(Request& r, const S } if(!file_executable(*file_spec)) - throw Exception(0, + throw Exception("email.send", file_spec, "is not executable." #ifdef PA_FORCED_SENDMAIL @@ -369,7 +382,7 @@ static void sendmail(Request& r, const S &argv, in, out, err); if(exit_status || err.size()) - throw Exception(0, + throw Exception("email.send", &method_name, "'%s' reported problem: %s (%d)", file_spec->cstr(), @@ -391,10 +404,18 @@ static void _send(Request& r, const Stri &method_name, "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*/? - message_hash_to_string(r, method_name, *hash, 0, &from, &to) : // old - static_cast(r.self)->message_hash_to_string(r, &method_name, hash, 0, &from, &to); // new + message_hash_to_string(r, method_name, *hash, 0, &from, to_param) : // old + static_cast(r.get_self())->message_hash_to_string(r, &method_name, hash, 0, &from, to_param); // new //r.write_pass_lang(message); sendmail(r, method_name, message, from, to); @@ -413,7 +434,7 @@ void MMail::configure_user(Request& r) { Pool& pool=r.pool(); // $MAIN:MAIL[$SMTP[mail.design.ru]] - if(Value *mail_element=r.main_class->get_element(mail_name)) + if(Value *mail_element=r.main_class.get_element(mail_name, r.main_class, false)) if(Hash *mail_conf=mail_element->get_hash(0)) r.classes_conf.put(name(), mail_conf); else