--- parser3/src/classes/mail.C 2002/06/24 11:59:31 1.67 +++ parser3/src/classes/mail.C 2002/07/31 14:35:57 1.71 @@ -4,7 +4,7 @@ Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - $Id: mail.C,v 1.67 2002/06/24 11:59:31 paf Exp $ + $Id: mail.C,v 1.71 2002/07/31 14:35:57 paf Exp $ */ #include "pa_config_includes.h" @@ -42,6 +42,7 @@ public: MMail(Pool& pool); public: // Methoded bool used_directly() { return false; } + void configure_user(Request& r); private: String mail_name; }; @@ -98,6 +99,8 @@ struct Mail_info { const String **from, **to; }; #endif + +const String& extractEmail(const String& string); static void add_header_attribute(const Hash::Key& aattribute, Hash::Val *ameaning, void *info) { @@ -111,9 +114,9 @@ static void add_header_attribute(const H // fetch from & to from header for SMTP if(mi.from && aattribute=="from") - *mi.from=&lmeaning.as_string(); + *mi.from=&extractEmail(lmeaning.as_string()); if(mi.to && aattribute=="to") - *mi.to=&lmeaning.as_string(); + *mi.to=&extractEmail(lmeaning.as_string()); // append header line *mi.header << @@ -266,15 +269,15 @@ static void sendmail(Request& r, const S char *message_cstr=message.cstr(); Hash *mail_conf=static_cast(r.classes_conf.get(mail_base_class->name())); -#ifdef _MSC_VER if(!from) throw Exception("parser.runtime", &method_name, - "has no 'from' header specified"); + "parameter does not specify 'from' header field"); if(!to) throw Exception("parser.runtime", &method_name, - "has no 'to' header specified"); + "parameter does not specify 'to' header field"); +#ifdef _MSC_VER SMTP& smtp=*new(pool) SMTP(pool, method_name); Value *server_port; @@ -294,8 +297,8 @@ static void sendmail(Request& r, const S "$"MAIN_CLASS_NAME":"MAIL_NAME".SMTP not defined"); #else // unix - // $MAIN:MAIL.sendmail["/usr/sbin/sendmail -t"] default - // $MAIN:MAIL.sendmail["/usr/lib/sendmail -t"] default + // $MAIN:MAIL.sendmail["/usr/sbin/sendmail -t -i -f postmaster"] default + // $MAIN:MAIL.sendmail["/usr/lib/sendmail -t -i -f postmaster"] default const String *sendmail_command; #ifdef PA_FORCED_SENDMAIL @@ -314,12 +317,21 @@ static void sendmail(Request& r, const S String *test=new(pool) String(pool, "/usr/sbin/sendmail"); if(!file_executable(*test)) test=new(pool) String(pool, "/usr/lib/sendmail"); - test->APPEND_CONST(" -ti"); + test->APPEND_CONST(" -t -i -f postmaster"); sendmail_command=test; } #endif - // we know sendmail_command here + // we know sendmail_command here, should replace "postmaster" with "$from" from message + int at_postmaster=sendmail_command->pos("postmaster"); + if(at_postmaster>0) { + String& reconstructed=sendmail_command->mid(0, at_postmaster); + reconstructed << *from; + reconstructed << sendmail_command->mid(at_postmaster+10/*postmaster*/, sendmail_command->size()); + sendmail_command=&reconstructed; + } + + // execute it Array argv(pool); const String *file_spec; int after_file_spec=sendmail_command->pos(" ", 1); @@ -338,7 +350,7 @@ static void sendmail(Request& r, const S #ifdef PA_FORCED_SENDMAIL " Use configure key \"--with-sendmail=appropriate sendmail command\"" #else - " Set $"MAIN_CLASS_NAME":"MAIL_NAME".%s with appropriate sendmail command", + " Set $"MAIN_CLASS_NAME":"MAIL_NAME".%s to appropriate sendmail command", sendmailkey_cstr #endif ); @@ -397,6 +409,20 @@ MMail::MMail(Pool& apool) : Methoded(apo add_native_method("send", Method::CT_STATIC, _send, 1, 1); } +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(Hash *mail_conf=mail_element->get_hash(0)) + r.classes_conf.put(name(), mail_conf); + else + if( !mail_element->is_string() ) + throw Exception("parser.runtime", + 0, + "$" MAIL_CLASS_NAME ":" MAIL_NAME " is not hash"); +} + // creator Methoded *MMail_create(Pool& pool) {