Diff for /parser3/src/classes/mail.C between versions 1.24 and 1.33

version 1.24, 2001/04/28 10:58:26 version 1.33, 2001/07/18 10:06:04
Line 7 Line 7
   
         $Id$          $Id$
 */  */
   static const char *RCSId="$Id$"; 
   
 #include "pa_config_includes.h"  #include "pa_config_includes.h"
   
Line 23 Line 24
   
 #define MAIL_CLASS_NAME "mail"  #define MAIL_CLASS_NAME "mail"
   
   #define MAIL_NAME "MAIL"
   
   // global variable
   
   Methoded *mail_class;
   
 // class  // class
   
 class MMail : public Methoded {  class MMail : public Methoded {
Line 31  public: Line 38  public:
 public: // Methoded  public: // Methoded
         bool used_directly() { return true; }          bool used_directly() { return true; }
         void configure_user(Request& r);          void configure_user(Request& r);
   private:
           String mail_name;
           String content_disposition_name;
           String content_disposition_filename_name;
 };  };
   
 // helpers  // helpers
Line 109  static void uuencode(String& result, con Line 120  static void uuencode(String& result, con
                 "end\n";                  "end\n";
 }  }
   
 /// ^mail:send[$attach[$type[uue|mime64] $value[DATA]]]   /** ^mail:send[$attach[$type[uue|mime64] $value[DATA]]] 
           @todo solve - bad with html attaches
   */
 static const String& attach_hash_to_string(Request& r, const String& origin_string,   static const String& attach_hash_to_string(Request& r, const String& origin_string, 
                                                                                    Hash& attach_hash) {                                                                                     Hash& attach_hash) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
Line 196  static void add_header_attribute(const H Line 209  static void add_header_attribute(const H
 }  }
   
 /// used in mail: _send / letter_hash_to_string / add_part  /// used in mail: _send / letter_hash_to_string / add_part
 struct Seq_item {  struct Mail_seq_item {
         const String *part_name;          const String *part_name;
         Value *part_value;          Value *part_value;
 };  };
 static void add_part(const Hash::Key& part_name, Hash::Val *part_value,   static void add_part(const Hash::Key& part_name, Hash::Val *part_value, 
                                          void *info) {                                           void *info) {
         Seq_item **seq_ref=static_cast<Seq_item **>(info);          Mail_seq_item **seq_ref=static_cast<Mail_seq_item **>(info);
         (**seq_ref).part_name=&part_name;          (**seq_ref).part_name=&part_name;
         (**seq_ref).part_value=static_cast<Value *>(part_value);          (**seq_ref).part_value=static_cast<Value *>(part_value);
         (*seq_ref)++;          (*seq_ref)++;
 }  }
 static double key_of_part(const void *item) {  static double key_of_part(const void *item) {
         const char *cstr=static_cast<const Seq_item *>(item)->part_name->cstr();          const char *cstr=static_cast<const Mail_seq_item *>(item)->part_name->cstr();
         char *error_pos;          char *error_pos;
         return strtod(cstr, &error_pos);          return strtod(cstr, &error_pos);
 }  }
Line 265  static const String& letter_hash_to_stri Line 278  static const String& letter_hash_to_stri
   
                         // body parts..                          // body parts..
                         // ..collect                          // ..collect
                         Seq_item *seq=(Seq_item *)malloc(sizeof(Seq_item)*body_hash->size());                          Mail_seq_item *seq=(Mail_seq_item *)malloc(sizeof(Mail_seq_item)*body_hash->size());
                         Seq_item *seq_ref=seq;  body_hash->for_each(add_part, &seq_ref);                          Mail_seq_item *seq_ref=seq;  body_hash->for_each(add_part, &seq_ref);
                         // ..sort                          // ..sort
                         _qsort(seq, body_hash->size(), sizeof(Seq_item),                           _qsort(seq, body_hash->size(), sizeof(Mail_seq_item), 
                                 sort_cmp_string_double_value);                                  sort_cmp_string_double_value);
                         // ..insert in 'seq' order                          // ..insert in 'seq' order
                         for(int i=0; i<body_hash->size(); i++) {                          for(int i=0; i<body_hash->size(); i++) {
Line 308  static void sendmail(Request& r, const S Line 321  static void sendmail(Request& r, const S
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
         char *letter_cstr=letter.cstr();          char *letter_cstr=letter.cstr();
           Hash *mail_conf=static_cast<Hash *>(r.classes_conf.get(mail_class->name()));
   
 #ifdef _MSC_VER  #ifdef _MSC_VER
         if(!from)          if(!from)
Line 321  static void sendmail(Request& r, const S Line 335  static void sendmail(Request& r, const S
   
         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.yourdomain.ru[:port]]
         if(r.mail &&           if(mail_conf && 
                 (server_port=static_cast<Value *>(r.mail->get(                  (server_port=static_cast<Value *>(mail_conf->get(
                         *new(pool) String(pool, "SMTP"))))) {                          *new(pool) String(pool, "SMTP"))))) {
                 char *server=server_port->as_string().cstr();                  char *server=server_port->as_string().cstr();
                 const char *port=rsplit(server, ':');                  const char *port=rsplit(server, ':');
Line 339  static void sendmail(Request& r, const S Line 353  static void sendmail(Request& r, const S
         // unix          // unix
         // $MAIN:MAIL.prog1["/usr/sbin/sendmail -t"] default          // $MAIN:MAIL.prog1["/usr/sbin/sendmail -t"] default
         // $MAIN:MAIL.prog2["/usr/lib/sendmail -t"] default          // $MAIN:MAIL.prog2["/usr/lib/sendmail -t"] default
         if(r.mail) {          if(mail_conf) {
                 char no_cstr[MAX_NUMBER];                  char no_cstr[MAX_NUMBER];
                 for(int no=-2; ; no++) {                  for(int no=-2; ; no++) {
                         const String *prog_string;                          const String *prog_string;
Line 351  static void sendmail(Request& r, const S Line 365  static void sendmail(Request& r, const S
                                         String prog_key(pool, "prog");                                          String prog_key(pool, "prog");
                                         snprintf(no_cstr, MAX_NUMBER, "%d", no);                                          snprintf(no_cstr, MAX_NUMBER, "%d", no);
                                         prog_key << no_cstr;                                          prog_key << no_cstr;
                                         if(Value *prog_value=static_cast<Value *>(r.mail->get(prog_key)))                                          if(Value *prog_value=static_cast<Value *>(mail_conf->get(prog_key)))
                                                 prog_string=&prog_value->as_string();                                                  prog_string=&prog_value->as_string();
                                         else                                          else
                                                 if(no==0)                                                  if(no==0)
Line 403  static void sendmail(Request& r, const S Line 417  static void sendmail(Request& r, const S
   
 // methods  // methods
   
 /// ^mail:send{hash}  
 static void _send(Request& r, const String& method_name, MethodParams *params) {  static void _send(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
         Value& vhash=params->get_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();          Hash *hash=vhash.get_hash();
         if(!hash)          if(!hash)
                 PTHROW(0, 0,                  PTHROW(0, 0,
Line 423  static void _send(Request& r, const Stri Line 436  static void _send(Request& r, const Stri
   
 // constructor & configurator  // constructor & configurator
   
 MMail::MMail(Pool& apool) : Methoded(apool) {  MMail::MMail(Pool& apool) : Methoded(apool),
           mail_name(apool, MAIL_NAME),
           content_disposition_name(apool, CONTENT_DISPOSITION_NAME),
           content_disposition_filename_name(apool, CONTENT_DISPOSITION_FILENAME_NAME)
   {
         set_name(*NEW String(pool(), MAIL_CLASS_NAME));          set_name(*NEW String(pool(), MAIL_CLASS_NAME));
   
         /// ^mail:send{hash}          // ^mail:send{hash}
         add_native_method("send", Method::CT_STATIC, _send, 1, 1);          add_native_method("send", Method::CT_STATIC, _send, 1, 1);
 }  }
   
Line 434  void MMail::configure_user(Request& r) { Line 451  void MMail::configure_user(Request& r) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
         // $MAIN:MAIL[$SMTP[mail.design.ru]]          // $MAIN:MAIL[$SMTP[mail.design.ru]]
         if(Value *mail_element=r.main_class->get_element(*mail_name))          if(Value *mail_element=r.main_class->get_element(mail_name))
                 if(!(r.mail=mail_element->get_hash()))                  if(Hash *mail_conf=mail_element->get_hash())
                           r.classes_conf.put(name(), mail_conf);
                   else
                         PTHROW(0, 0,                          PTHROW(0, 0,
                                 0,                                  0,
                                 "$" MAIL_CLASS_NAME ":" MAIL_NAME " is not hash");                                  "$" MAIL_CLASS_NAME ":" MAIL_NAME " is not hash");
 }  }
   
 // global variable  
   
 Methoded *mail_class;  
   
 // creator  // creator
   
 Methoded *MMail_create(Pool& pool) {  Methoded *MMail_create(Pool& pool) {

Removed from v.1.24  
changed lines
  Added in v.1.33


E-mail: