--- parser3/src/classes/mail.C 2002/02/06 08:54:22 1.52 +++ parser3/src/classes/mail.C 2002/06/12 12:50:32 1.65 @@ -1,10 +1,10 @@ /** @file Parser: @b mail parser class. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) + Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) - $Id: mail.C,v 1.52 2002/02/06 08:54:22 paf Exp $ + $Id: mail.C,v 1.65 2002/06/12 12:50:32 paf Exp $ */ #include "pa_config_includes.h" @@ -44,8 +44,6 @@ public: // Methoded void configure_user(Request& r); private: String mail_name; - String content_disposition_name; - String content_disposition_filename_name; }; // helpers @@ -137,7 +135,7 @@ static const String& attach_hash_to_stri if(Value *value=static_cast(attach_hash.get(*value_name))) vfile=value->as_vfile(String::UL_AS_IS); // bad with html attaches. todo: solve else - throw Exception(0, 0, + throw Exception("parser.runtime", &origin_string, "has no $value"); @@ -152,7 +150,8 @@ static const String& attach_hash_to_stri String& result=*new(pool) String(pool); // content-type: application/octet-stream - result << "content-type: " << r.mime_type_of(file_name_cstr) << "\n"; + result << "content-type: " << r.mime_type_of(file_name_cstr) + << "; name=\"" << file_name_cstr << "\"\n"; // content-disposition: attachment; filename="user_file_name" result << "content-disposition: attachment; filename=\"" << file_name_cstr << "\"\n"; @@ -160,7 +159,7 @@ static const String& attach_hash_to_stri if(!type/*default = uue*/ || *type=="uue") { uuencode(result, file_name_cstr, *vfile); } else // for now - throw Exception(0, 0, + throw Exception("parser.runtime", type, "unknown attachment encode format"); @@ -170,7 +169,7 @@ static const String& attach_hash_to_stri #ifndef DOXYGEN struct Mail_info { - Charset *charset; + Charset *charset; const char *content_charset_name; String *header; const String **from, **to; }; @@ -196,7 +195,7 @@ static void add_header_attribute(const H *mi.header << aattribute << ":" << attributed_meaning_to_string(lmeaning, String::UL_MAIL_HEADER). - cstr(String::UL_UNSPECIFIED, 0, mi.charset) << + cstr(String::UL_UNSPECIFIED, 0, mi.charset, mi.content_charset_name) << "\n"; } @@ -216,7 +215,7 @@ static int get_part_name_weight(const Ha cstr+=6; offset=ATTACHMENT_WEIGHT; } else - throw Exception(0, 0, + throw Exception("parser.runtime", &part_name, "is neither text# nor attach#"); @@ -246,17 +245,23 @@ static const String& letter_hash_to_stri String& result=*new(pool) String(pool); Charset *charset; - if(Value *vcharset_name=static_cast(letter_hash.get(*charset_name))) - charset=&charsets->get_charset(vcharset_name->as_string()); + if(Value *vrecodecharset_name=static_cast(letter_hash.get(*charset_name))) + charset=&charsets->get_charset(vrecodecharset_name->as_string()); else charset=&pool.get_source_charset(); + const char *content_charset_name=0; + if(Value *vcontent_type=static_cast(letter_hash.get(*content_type_name))) + if(Hash *hcontent_type=vcontent_type->get_hash(0)) + if(Value *vcontentcharset_name=static_cast(hcontent_type->get(*charset_name))) + content_charset_name=vcontentcharset_name->as_string().cstr(); + if(from) *from=0; if(to) *to=0; Mail_info mail_info={ - charset, + charset, content_charset_name, &result, from, to }; @@ -298,7 +303,7 @@ static const String& letter_hash_to_stri result << letter_hash_to_string(r, method_name, *part_hash, level+1, 0, 0); else - throw Exception(0, 0, + throw Exception("parser.runtime", seq[i].name, "part is not hash"); } @@ -322,7 +327,7 @@ static const String& letter_hash_to_stri result.APPEND_CLEAN((const char*)mail_ptr, mail_size, 0, 0); } } else - throw Exception(0, 0, + throw Exception("parser.runtime", &method_name, "has no $body"); @@ -339,11 +344,11 @@ static void sendmail(Request& r, const S #ifdef _MSC_VER if(!from) - throw Exception(0, 0, + throw Exception("parser.runtime", &method_name, "has no 'from' header specified"); if(!to) - throw Exception(0, 0, + throw Exception("parser.runtime", &method_name, "has no 'to' header specified"); @@ -360,7 +365,7 @@ static void sendmail(Request& r, const S smtp.Send(server, port, letter_cstr, from->cstr(), to->cstr()); } else - throw Exception(0, 0, + throw Exception("parser.runtime", &method_name, "$"MAIN_CLASS_NAME":"MAIL_NAME".SMTP not defined"); #else @@ -368,13 +373,16 @@ static void sendmail(Request& r, const S // $MAIN:MAIL.sendmail["/usr/sbin/sendmail -t"] default // $MAIN:MAIL.sendmail["/usr/lib/sendmail -t"] default - const char *sendmailkey_cstr="sendmail"; const String *sendmail_command; +#ifdef PA_FORCED_SENDMAIL + sendmail_command=new(pool) String(pool, PA_FORCED_SENDMAIL); +#else + const char *sendmailkey_cstr="sendmail"; if(mail_conf) { if(Value *sendmail_value=static_cast(mail_conf->get(String(pool, sendmailkey_cstr)))) sendmail_command=&sendmail_value->as_string(); else - throw Exception(0, 0, + throw Exception("parser.runtime", &method_name, "$"MAIN_CLASS_NAME":"MAIL_NAME".%s not defined", sendmailkey_cstr); @@ -385,6 +393,7 @@ static void sendmail(Request& r, const S test->APPEND_CONST(" -t"); sendmail_command=test; } +#endif // we know sendmail_command here Array argv(pool); @@ -399,18 +408,32 @@ static void sendmail(Request& r, const S } if(!file_executable(*file_spec)) - throw Exception(0, 0, - file_spec, - "is not executable. Set $"MAIN_CLASS_NAME":"MAIL_NAME".%s with appropriate sendmail command", - sendmailkey_cstr); + throw Exception(0, + file_spec, + "is not executable." +#ifdef PA_FORCED_SENDMAIL + " Use configure key \"--with-sendmail=appropriate sendmail command\"" +#else + " Set $"MAIN_CLASS_NAME":"MAIL_NAME".%s with appropriate sendmail command", + sendmailkey_cstr +#endif + ); + String in(pool, letter_cstr); String out(pool); String err(pool); - int exit_status=pa_exec(*file_spec, + int exit_status=pa_exec( + // forced_allow +#ifdef PA_FORCED_SENDMAIL + true +#else + false +#endif + , *file_spec, 0/*default env*/, &argv, in, out, err); if(exit_status || err.size()) - throw Exception(0, 0, + throw Exception(0, &method_name, "'%s' reported problem: %s (%d)", file_spec->cstr(), @@ -428,26 +451,21 @@ static void _send(Request& r, const Stri Value& vhash=params->as_no_junction(0, "message must not be code"); Hash *hash=vhash.get_hash(&method_name); if(!hash) - throw Exception(0, 0, + throw Exception("parser.runtime", &method_name, "message must be hash"); const String *from, *to; const String& letter=letter_hash_to_string(r, method_name, *hash, 0, &from, &to); -// r.write_assign_lang(*new(pool) VString(letter)); sendmail(r, method_name, letter, from, to); } // constructor & configurator -MMail::MMail(Pool& apool) : Methoded(apool), - mail_name(apool, MAIL_NAME), - content_disposition_name(apool, CONTENT_DISPOSITION_NAME), - content_disposition_filename_name(apool, CONTENT_DISPOSITION_FILENAME_NAME) +MMail::MMail(Pool& apool) : Methoded(apool, MAIL_CLASS_NAME), + mail_name(apool, MAIL_NAME) { - set_name(*NEW String(pool(), MAIL_CLASS_NAME)); - // ^mail:send{hash} add_native_method("send", Method::CT_STATIC, _send, 1, 1); } @@ -459,10 +477,10 @@ void MMail::configure_user(Request& r) { if(Value *mail_element=r.main_class->get_element(mail_name)) if(Hash *mail_conf=mail_element->get_hash(0)) r.classes_conf.put(name(), mail_conf); - else - throw Exception(0, 0, + else if(!mail_element->get_string()) + throw Exception("parser.runtime", 0, - "$" MAIL_CLASS_NAME ":" MAIL_NAME " is not hash"); + "$" MAIN_CLASS_NAME ":" MAIL_NAME " is not hash"); } // creator