--- parser3/src/classes/mail.C 2002/12/05 15:00:00 1.84 +++ parser3/src/classes/mail.C 2003/02/04 15:15:02 1.88.2.5 @@ -1,13 +1,14 @@ /** @file Parser: @b mail parser class. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_MAIL_C="$Date: 2002/12/05 15:00:00 $"; +static const char* IDENT_MAIL_C="$Date: 2003/02/04 15:15:02 $"; #include "pa_config_includes.h" +#include "pa_vmethod_frame.h" #include "pa_common.h" #include "pa_request.h" @@ -33,7 +34,7 @@ const int ATTACHMENT_WEIGHT=100; // global variable -Methoded *mail_base_class; +MethodedPtr mail_base_class; // class @@ -70,7 +71,7 @@ static const String& attach_hash_to_stri file_name=&vfile_name->as_string(); else // no $file-name, VFile surely knows name file_name=&static_cast(vfile->fields().get(*name_name))->as_string(); - const char *file_name_cstr=file_name->cstr(); + const char* file_name_cstr=file_name->cstr(); String& result=*new(pool) String(pool); @@ -94,7 +95,7 @@ static const String& attach_hash_to_stri #ifndef DOXYGEN struct Mail_info { - Charset *charset; const char *content_charset_name; + Charset *charset; const char* content_charset_name; String *header; const String **from; String **to; @@ -141,7 +142,7 @@ struct Mail_seq_item { }; #endif static int get_part_name_weight(const Hash::Key& part_name) { - const char *cstr=part_name.cstr(); + const char* cstr=part_name.cstr(); int offset=0; if(strncmp(cstr, "text", 4)==0) { cstr+=4; @@ -184,7 +185,7 @@ static const String& message_hash_to_str else charset=&pool.get_source_charset(); - const char *content_charset_name=0; + const char* content_charset_name=0; if(Value *vcontent_type=static_cast(message_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))) @@ -255,7 +256,7 @@ static const String& message_hash_to_str "\n"; // header|body separator const String& body=body_element->as_string(); - const char *body_ptr=body.cstr(String::UL_UNSPECIFIED); // 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; @@ -266,7 +267,7 @@ static const String& message_hash_to_str } } else throw Exception("parser.runtime", - &method_name, + method_name, "has no $body"); return result; @@ -280,16 +281,17 @@ static void sendmail(Request& r, const S char *message_cstr=message.cstr(String::UL_UNSPECIFIED); Hash *mail_conf=static_cast(r.classes_conf.get(mail_base_class->name())); - const char *exception_type="email.format"; - if(!from) + const char* exception_type="email.format"; + if(!from) // we use in sendmail -f {from} && SMTP MAIL from: {from} throw Exception(exception_type, - &method_name, + method_name, "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, - &method_name, + method_name, "parameter does not specify 'to' header field"); -#ifdef _MSC_VER SMTP& smtp=*new(pool) SMTP(pool, method_name); Value *server_port; @@ -298,14 +300,14 @@ static void sendmail(Request& r, const S (server_port=static_cast(mail_conf->get( *new(pool) String(pool, "SMTP"))))) { char *server=server_port->as_string().cstr(); - const char *port=rsplit(server, ':'); + const char* port=rsplit(server, ':'); if(!port) port="25"; smtp.Send(server, port, message_cstr, from->cstr(), to->cstr()); } else throw Exception("parser.runtime", - &method_name, + method_name, "$"MAIN_CLASS_NAME":"MAIL_NAME".SMTP not defined"); #else // unix @@ -313,26 +315,33 @@ static void sendmail(Request& r, const S // $MAIN:MAIL.sendmail["/usr/lib/sendmail -t -i -f postmaster"] default const String *sendmail_command; + const char* sendmailkey_cstr="sendmail"; + if(mail_conf) { #ifdef PA_FORCED_SENDMAIL - sendmail_command=new(pool) String(pool, 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 - 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("parser.runtime", - &method_name, + method_name, "$"MAIN_CLASS_NAME":"MAIL_NAME".%s not defined", sendmailkey_cstr); +#endif } else { +#ifdef PA_FORCED_SENDMAIL + sendmail_command=new(pool) String(pool, PA_FORCED_SENDMAIL); +#else String *test=new(pool) String(pool, "/usr/sbin/sendmail"); if(!file_executable(*test)) test=new(pool) String(pool, "/usr/lib/sendmail"); test->APPEND_CONST(" -t -i -f postmaster"); sendmail_command=test; - } #endif + } // we know sendmail_command here, should replace "postmaster" with "$from" from message int at_postmaster=sendmail_command->pos("postmaster"); @@ -382,7 +391,7 @@ static void sendmail(Request& r, const S in, out, err); if(exit_status || err.size()) throw Exception("email.send", - &method_name, + method_name, "'%s' reported problem: %s (%d)", file_spec->cstr(), err.size()?err.cstr():"UNKNOWN", @@ -393,20 +402,20 @@ static void sendmail(Request& r, const S // methods -static void _send(Request& r, const String& method_name, MethodParams *params) { +static void _send(Request& r, StringPtr method_name, MethodParams& params) { Pool& pool=r.pool(); - Value& vhash=params->as_no_junction(0, "message must not be code"); + Value& vhash=params.as_no_junction(0, "message must not be code"); Hash *hash=vhash.get_hash(&method_name); if(!hash) throw Exception("parser.runtime", - &method_name, + method_name, "message must be hash"); - const String *from; - String *to; + const String *from=0; + String *to=0; String **to_param= -#ifdef WIN32 +#ifdef _MSC_VER &to #else 0 @@ -414,7 +423,7 @@ static void _send(Request& r, const Stri ; const String& message=hash->get(*body_name)/*old format*/? 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 + 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);