|
|
| version 1.11, 2001/04/10 06:57:21 | version 1.18, 2001/04/15 13:12:17 |
|---|---|
| Line 18 | Line 18 |
| #include "pa_common.h" | #include "pa_common.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vfile.h" | #include "pa_vfile.h" |
| #include "pa_exec.h" | |
| // global var | // global var |
| Line 43 static void uuencode(String& result, con | Line 44 static void uuencode(String& result, con |
| result << "begin 644 " << file_name_cstr << "\n"; | result << "begin 644 " << file_name_cstr << "\n"; |
| //body | //body |
| const unsigned char *itemp; | |
| int index; | |
| int count=45; | |
| const unsigned char *in=(const unsigned char *)vfile.value_ptr(); | const unsigned char *in=(const unsigned char *)vfile.value_ptr(); |
| size_t in_length=vfile.value_size(); | size_t in_length=vfile.value_size(); |
| for(itemp=in; itemp<(in+in_length); itemp+=count) { | int count=45; |
| for(const unsigned char *itemp=in; itemp<(in+in_length); itemp+=count) { | |
| int index; | |
| if((itemp+count)>(in+in_length)) | if((itemp+count)>(in+in_length)) |
| count=in_length-(itemp-in); | count=in_length-(itemp-in); |
| Line 114 static const String& attach_hash_to_stri | Line 113 static const String& attach_hash_to_stri |
| const VFile *vfile; | const VFile *vfile; |
| if(Value *value=static_cast<Value *>(attach_hash.get(*value_name))) | if(Value *value=static_cast<Value *>(attach_hash.get(*value_name))) |
| vfile=value->as_vfile(); | vfile=value->as_vfile(String::UL_AS_IS); // bad with html attaches. todo: solve |
| else | else |
| PTHROW(0, 0, | PTHROW(0, 0, |
| &origin_string, | &origin_string, |
| Line 124 static const String& attach_hash_to_stri | Line 123 static const String& attach_hash_to_stri |
| if(Value *vfile_name=static_cast<Value *>(attach_hash.get( | if(Value *vfile_name=static_cast<Value *>(attach_hash.get( |
| *new(pool) String(pool, "file-name")))) // specified $file-name | *new(pool) String(pool, "file-name")))) // specified $file-name |
| file_name=&vfile_name->as_string(); | file_name=&vfile_name->as_string(); |
| else // no $file-name | else // no $file-name, VFile surely knows name |
| if(Value *vfile_name=static_cast<Value *>(vfile->fields().get(*name_name))) | file_name=&static_cast<Value *>(vfile->fields().get(*name_name))->as_string(); |
| file_name=&vfile_name->as_string(); // VFile knows name | |
| else // vfile doesn't know name | |
| file_name=new(pool) String(pool, "noname.dat"); | |
| const char *file_name_cstr=file_name->cstr(String::UL_FILE_NAME); | const char *file_name_cstr=file_name->cstr(String::UL_FILE_NAME); |
| String& result=*new(pool) String(pool); | String& result=*new(pool) String(pool); |
| Line 217 static const String& letter_hash_to_stri | Line 213 static const String& letter_hash_to_stri |
| // prepare header: 'hash' without "body" | // prepare header: 'hash' without "body" |
| String& result=*new(pool) String(pool); | String& result=*new(pool) String(pool); |
| *from=*to=0; | |
| Mail_info mail_info={ | Mail_info mail_info={ |
| /*excluding*/ body_name, | /*excluding*/ body_name, |
| &result, | &result, |
| Line 272 static const String& letter_hash_to_stri | Line 269 static const String& letter_hash_to_stri |
| return result; | return result; |
| } | } |
| /// @test unix ver | |
| static void sendmail(Request& r, const String& method_name, | static void sendmail(Request& r, const String& method_name, |
| const String& letter, | const String& letter, |
| const String *from, const String *to) { | const String *from, const String *to) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| char *letter_cstr=letter.cstr(); | |
| #ifdef WIN32 | #ifdef WIN32 |
| if(!from) | if(!from) |
| PTHROW(0, 0, | PTHROW(0, 0, |
| &method_name, | &method_name, |
| "not specified 'from'"); | "has no 'from' header specified"); |
| if(!to) | if(!to) |
| PTHROW(0, 0, | PTHROW(0, 0, |
| &method_name, | &method_name, |
| "not specified 'to'"); | "has no 'to' header specified"); |
| char *letter_cstr=letter.cstr(); | |
| SMTP& smtp=*new(pool) SMTP(pool, method_name); | SMTP& smtp=*new(pool) SMTP(pool, method_name); |
| Value *server_port; | Value *server_port; |
| // $MAIN:MAIL.SMTP[mail.design.ru] | // $MAIN:MAIL.SMTP[mail.design.ru] |
| Line 304 static void sendmail(Request& r, const S | Line 301 static void sendmail(Request& r, const S |
| } else | } else |
| PTHROW(0, 0, | PTHROW(0, 0, |
| &method_name, | &method_name, |
| "$MAIN:MAIL.SMTP not defined"); | "$"MAIN_CLASS_NAME":"MAIL_NAME".SMTP not defined"); |
| #else | #else |
| PTHROW(0, 0, | // unix |
| &method_name, | // $MAIN:MAIL.prog1["/usr/sbin/sendmail -t"] default |
| "todo"); | // $MAIN:MAIL.prog2["/usr/lib/sendmail -t"] default |
| if(r.mail) { | |
| char no_cstr[MAX_NUMBER]; | |
| for(int no=-2; ; no++) { | |
| const String *prog_string; | |
| switch(no) { | |
| case -2: prog_string=new(pool) String(pool, "/usr/sbin/sendmail -t"); break; | |
| case -1: prog_string=new(pool) String(pool, "/usr/lib/sendmail -t"); break; | |
| default: | |
| { | |
| String prog_key(pool, "prog"); | |
| snprintf(no_cstr, MAX_NUMBER, "%d", no); | |
| prog_key << no_cstr; | |
| if(Value *prog_value=static_cast<Value *>(r.mail->get(prog_key))) | |
| prog_string=&prog_value->as_string(); | |
| else | |
| if(no==0) | |
| continue; | |
| else | |
| PTHROW(0, 0, | |
| &method_name, | |
| "$"MAIN_CLASS_NAME":"MAIL_NAME".%s not defined", | |
| prog_key.cstr()); | |
| } | |
| } | |
| // we know prog_string here | |
| Array argv(pool); | |
| const String *file_spec; | |
| int after_file_spec=prog_string->pos(" ", 1); | |
| if(after_file_spec<=0) | |
| file_spec=prog_string; | |
| else { | |
| size_t pos_after=after_file_spec; | |
| file_spec=&prog_string->mid(0, pos_after); | |
| prog_string->split(argv, &pos_after, " ", 1, String::UL_CLEAN); | |
| } | |
| // skip unavailable default programs | |
| if(no<0 && !file_executable(*file_spec)) | |
| continue; | |
| String in(pool, letter_cstr); String out(pool); String err(pool); | |
| int exit_status=pa_exec(*file_spec, | |
| 0/*default env*/, | |
| &argv, | |
| in, out, err); | |
| if(exit_status || err.size()) | |
| PTHROW(0, 0, | |
| &method_name, | |
| "'%s' reported problem: %s (%d)", | |
| file_spec->cstr(), | |
| err.size()?err.cstr():"UNKNOWN", | |
| exit_status); | |
| break; | |
| } | |
| } else | |
| PTHROW(0, 0, | |
| &method_name, | |
| "$"MAIN_CLASS_NAME":"MAIL_NAME" not defined"); | |
| #endif | #endif |
| } | } |
| // methods | // methods |
| static void _send(Request& r, const String& method_name, Array *params) { | static void _send(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& vhash=*static_cast<Value *>(params->get(0)); | Value& vhash=params->get_no_junction(0, "message must not be code"); |
| // forcing [this body type] | |
| r.fail_if_junction_(true, vhash, method_name, "message must not be code"); | |
| Hash *hash=vhash.get_hash(); | Hash *hash=vhash.get_hash(); |
| if(!hash) | if(!hash) |
| PTHROW(0, 0, | PTHROW(0, 0, |