--- parser3/src/classes/mail.C 2023/09/26 20:49:06 1.136 +++ parser3/src/classes/mail.C 2026/11/05 11:40:32 1.140 @@ -1,7 +1,7 @@ /** @file Parser: @b mail parser class. - Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ @@ -19,7 +19,7 @@ #include "smtp.h" -volatile const char * IDENT_MAIL_C="$Id: mail.C,v 1.136 2023/09/26 20:49:06 moko Exp $"; +volatile const char * IDENT_MAIL_C="$Id: mail.C,v 1.140 2026/11/05 11:40:32 moko Exp $"; // defines @@ -35,7 +35,6 @@ const int ATTACHMENT_WEIGHT=100; class MMail: public Methoded { public: // Methoded bool used_directly() { return false; } - void configure_user(Request& r); public: MMail(); @@ -190,11 +189,18 @@ static void _send(Request& r, MethodPara if(Value* vdebug=hash->get(MAIL_DEBUG_NAME)) print_debug=vdebug->as_bool(); - Value* vmail_conf=static_cast(r.classes_conf.get(mail_class->type())); + Value* vmail_conf=r.main_class.get_element(mail_name); Value* smtp_server_port=0; + if(vmail_conf) { - // $MAIN:MAIL.SMTP[mail.yourdomain.ru[:port]] - smtp_server_port=vmail_conf->get_hash()->get("SMTP"); + if(vmail_conf->get_hash()) { + // $MAIN:MAIL.SMTP[mail.yourdomain.ru[:port]] + smtp_server_port=vmail_conf->get_hash()->get("SMTP"); + } else { + if( !vmail_conf->is_string() ) + throw Exception(PARSER_RUNTIME, 0, "$" MAIL_CLASS_NAME ":" MAIL_NAME " is not hash"); + vmail_conf=0; + } } const String* from=0; @@ -207,21 +213,22 @@ static void _send(Request& r, MethodPara sendmail(vmail_conf, smtp_server_port, message, from, to, soptions); } +static void _parse(Request& r, MethodParams& params) { +#ifdef WITH_MAILRECEIVE + VFile* message=params.as_no_junction(0, "message must be string or file").as_vfile(String::L_AS_IS, &r.charsets); + r.write(GET_SELF(r, VMail).parse_message(r, message->value_ptr(), message->value_size())); +#else + (void)r; (void)params; + throw Exception("mail", 0, "compiled without mailreceive support"); +#endif +} + // constructor & configurator MMail::MMail(): Methoded(MAIL_CLASS_NAME) { // ^mail:send{hash} add_native_method("send", Method::CT_STATIC, _send, 1, 1); -} - -void MMail::configure_user(Request& r) { - // $MAIN:MAIL[$SMTP[mail.design.ru]] - if(Value* mail_element=r.main_class.get_element(mail_name)) { - if(mail_element->get_hash()) - r.classes_conf.put(type(), mail_element); - else - if( !mail_element->is_string() ) - throw Exception(PARSER_RUNTIME, 0, "$" MAIL_CLASS_NAME ":" MAIL_NAME " is not hash"); - } + // ^mail:parse[string|file] + add_native_method("parse", Method::CT_STATIC, _parse, 1, 1); }