--- parser3/src/classes/mail.C 2001/04/23 09:38:40 1.21 +++ parser3/src/classes/mail.C 2001/04/28 10:58:26 1.24 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: mail.C,v 1.21 2001/04/23 09:38:40 paf Exp $ + $Id: mail.C,v 1.24 2001/04/28 10:58:26 paf Exp $ */ #include "pa_config_includes.h" @@ -14,15 +14,24 @@ # include "smtp/smtp.h" #endif -#include "_mail.h" #include "pa_common.h" #include "pa_request.h" #include "pa_vfile.h" #include "pa_exec.h" -// global var +// defines -VStateless_class *mail_class; +#define MAIL_CLASS_NAME "mail" + +// class + +class MMail : public Methoded { +public: + MMail(Pool& pool); +public: // Methoded + bool used_directly() { return true; } + void configure_user(Request& r); +}; // helpers @@ -155,6 +164,7 @@ static bool find_content_type_charset(co return StrEqNc(aattribute.cstr(), "charset"); } +/// used by mail: _send / letter_hash_to_string / add_header_attribute struct Mail_info { String *attribute_to_exclude; const char *charset; @@ -184,6 +194,8 @@ static void add_header_attribute(const H cstr(String::UL_UNSPECIFIED, 0, mi.charset) << "\n"; } + +/// used in mail: _send / letter_hash_to_string / add_part struct Seq_item { const String *part_name; Value *part_value; @@ -384,13 +396,14 @@ static void sendmail(Request& r, const S } else PTHROW(0, 0, &method_name, - "$"MAIN_CLASS_NAME":"MAIL_NAME" not defined"); + "$" MAIN_CLASS_NAME ":" MAIL_NAME " not defined"); #endif } // methods +/// ^mail:send{hash} static void _send(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -408,8 +421,32 @@ static void _send(Request& r, const Stri sendmail(r, method_name, letter, from, to); } -// initialize -void initialize_mail_class(Pool& pool, VStateless_class& vclass) { - // ^mail:send{hash} - vclass.add_native_method("send", Method::CT_STATIC, _send, 1, 1); +// constructor & configurator + +MMail::MMail(Pool& apool) : Methoded(apool) { + set_name(*NEW String(pool(), MAIL_CLASS_NAME)); + + /// ^mail:send{hash} + 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(!(r.mail=mail_element->get_hash())) + PTHROW(0, 0, + 0, + "$" MAIL_CLASS_NAME ":" MAIL_NAME " is not hash"); +} + +// global variable + +Methoded *mail_class; + +// creator + +Methoded *MMail_create(Pool& pool) { + return mail_class=new(pool) MMail(pool); }