Annotation of parser3/src/classes/mail.C, revision 1.1

1.1     ! paf         1: /** @file
        !             2:        Parser: @b mail parser class.
        !             3: 
        !             4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
        !             5: 
        !             6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
        !             7: 
        !             8:        $Id: mail.C,v 1.59 2001/04/06 13:41:29 paf Exp $
        !             9: */
        !            10: 
        !            11: #include "pa_config_includes.h"
        !            12: 
        !            13: #include "_mail.h"
        !            14: #include "pa_common.h"
        !            15: #include "pa_request.h"
        !            16: 
        !            17: // global var
        !            18: 
        !            19: VStateless_class *mail_class;
        !            20: 
        !            21: // methods
        !            22: 
        !            23: struct Mail_info {
        !            24:        String *attribute_to_exclude;
        !            25:        String *header;
        !            26: };
        !            27: 
        !            28: static void add_header_attribute(const Hash::Key& aattribute, Hash::Val *ameaning, 
        !            29:                                                                 void *info) {
        !            30: 
        !            31:        Value& lmeaning=*static_cast<Value *>(ameaning);
        !            32:        Mail_info& mi=*static_cast<Mail_info *>(info);
        !            33:        if(aattribute==*mi.attribute_to_exclude)
        !            34:                return;
        !            35: 
        !            36:        mi.header->append(aattribute, String::UL_PASS_APPENDED);
        !            37:        mi.header->APPEND_CONST(":");
        !            38:        mi.header->append(
        !            39:                attributed_meaning_to_string(lmeaning, String::UL_MAIL_HEADER), 
        !            40:                String::UL_PASS_APPENDED);
        !            41:        mi.header->APPEND_CONST("\n");
        !            42: }
        !            43: static void _send(Request& r, const String& method_name, Array *params) {
        !            44:        Pool& pool=r.pool();
        !            45: 
        !            46:        Value& vhash=*static_cast<Value *>(params->get(0));
        !            47:        // forcing [this body type]
        !            48:        r.fail_if_junction_(true, vhash, method_name, "message must not be code");
        !            49: 
        !            50:        Hash *hash=vhash.get_hash();
        !            51:        if(!hash)
        !            52:                PTHROW(0, 0,
        !            53:                        &method_name,
        !            54:                        "message must be hash");
        !            55: 
        !            56:        // prepare header: 'hash' without "body"
        !            57:        String& header=*new(pool) String(pool);
        !            58:        Mail_info mail_info={
        !            59:                /*excluding*/ body_name,
        !            60:                &header
        !            61:        };
        !            62:        hash->for_each(add_header_attribute, &mail_info);
        !            63: 
        !            64: 
        !            65:        r.write_assign_lang(*new(pool) VString(*mail_info.header));
        !            66: }
        !            67: 
        !            68: // initialize
        !            69: void initialize_mail_class(Pool& pool, VStateless_class& vclass) {
        !            70:        // ^mail:send{hash}
        !            71:        vclass.add_native_method("send", Method::CT_STATIC, _send, 1, 1);
        !            72: }

E-mail: