Diff for /parser3/src/classes/mail.C between versions 1.71 and 1.78

version 1.71, 2002/07/31 14:35:57 version 1.78, 2002/08/13 15:55:41
Line 3 Line 3
   
         Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
   
         $Id$  
 */  */
   
   static const char* IDENT_MAIL_C="$Date$";
   
 #include "pa_config_includes.h"  #include "pa_config_includes.h"
   
 #include "pa_common.h"  #include "pa_common.h"
Line 97  struct Mail_info { Line 97  struct Mail_info {
         Charset *charset; const char *content_charset_name;          Charset *charset; const char *content_charset_name;
         String *header;          String *header;
         const String **from, **to;          const String **from, **to;
           const String *errors_to;
 };  };
 #endif  #endif
   
 const String& extractEmail(const String& string);  const String& extractEmail(const String& string);
 static void add_header_attribute(const Hash::Key& aattribute, Hash::Val *ameaning,   static void add_header_attribute(const Hash::Key& raw_element_name, Hash::Val *aelement_value, 
                                                                  void *info) {                                                                   void *info) {
           Value& element_value=*static_cast<Value *>(aelement_value);
         Value& lmeaning=*static_cast<Value *>(ameaning);          const String& low_element_name=raw_element_name.change_case(raw_element_name.pool(), String::CC_LOWER);
         Mail_info& mi=*static_cast<Mail_info *>(info);          Mail_info& mi=*static_cast<Mail_info *>(info);
   
         // exclude one attribute [body]          // exclude one attribute [body]
         if(aattribute==BODY_NAME          if(low_element_name==BODY_NAME
                 || aattribute==CHARSET_NAME)                  || low_element_name==CHARSET_NAME)
                 return;                  return;
   
         // fetch from & to from header for SMTP          // fetch from & to from header for SMTP
         if(mi.from && aattribute=="from")          if(mi.from && low_element_name=="from")
                 *mi.from=&extractEmail(lmeaning.as_string());                  *mi.from=&extractEmail(element_value.as_string());
         if(mi.to && aattribute=="to")          if(mi.to && low_element_name=="to")
                 *mi.to=&extractEmail(lmeaning.as_string());                  *mi.to=&extractEmail(element_value.as_string());
           if(low_element_name=="errors-to")
                   mi.errors_to=&extractEmail(element_value.as_string());
   
         // append header line          // append header line
         *mi.header <<           *mi.header << 
                 aattribute << ":" <<                   low_element_name << ":" << 
                 attributed_meaning_to_string(lmeaning, String::UL_MAIL_HEADER).                  attributed_meaning_to_string(element_value, String::UL_MAIL_HEADER).
                         cstr(String::UL_UNSPECIFIED, 0, mi.charset, mi.content_charset_name) <<                           cstr(String::UL_UNSPECIFIED, 0, mi.charset, mi.content_charset_name) << 
                 "\n";                  "\n";
 }  }
Line 193  static const String& message_hash_to_str Line 196  static const String& message_hash_to_str
                 from, to                  from, to
         };          };
         message_hash.for_each(add_header_attribute, &mail_info);          message_hash.for_each(add_header_attribute, &mail_info);
           if(!mail_info.errors_to)
                   result << "errors-to: postmaster\n"; // errors-to: default
   
         if(Value *body_element=static_cast<Value *>(message_hash.get(*body_name))) {          if(Value *body_element=static_cast<Value *>(message_hash.get(*body_name))) {
                 if(Hash *body_hash=body_element->get_hash(&method_name)) {                  if(Hash *body_hash=body_element->get_hash(&method_name)) {
Line 244  static const String& message_hash_to_str Line 249  static const String& message_hash_to_str
                                 "\n"; // header|body separator                                  "\n"; // header|body separator
   
                         const String& body=body_element->as_string();                          const String& body=body_element->as_string();
                         const void *body_ptr=body.cstr();  // body                          const char *body_ptr=body.cstr(String::UL_UNSPECIFIED);  // body
                         size_t body_size=body.size();  // body                          size_t body_size=strlen(body_ptr);  // body
                         const void *mail_ptr;                          const void *mail_ptr;
                         size_t mail_size;                          size_t mail_size;
                         Charset::transcode(pool,                           Charset::transcode(pool, 
Line 266  static void sendmail(Request& r, const S Line 271  static void sendmail(Request& r, const S
                                          const String *from, const String *to) {                                           const String *from, const String *to) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
         char *message_cstr=message.cstr();          char *message_cstr=message.cstr(String::UL_UNSPECIFIED);
         Hash *mail_conf=static_cast<Hash *>(r.classes_conf.get(mail_base_class->name()));          Hash *mail_conf=static_cast<Hash *>(r.classes_conf.get(mail_base_class->name()));
   
           const char *exception_type="email.format";
         if(!from)          if(!from)
                 throw Exception("parser.runtime",                  throw Exception(exception_type,
                         &method_name,                          &method_name,
                         "parameter does not specify 'from' header field");                          "parameter does not specify 'from' header field");
         if(!to)          if(!to)
                 throw Exception("parser.runtime",                  throw Exception(exception_type,
                         &method_name,                          &method_name,
                         "parameter does not specify 'to' header field");                          "parameter does not specify 'to' header field");
 #ifdef _MSC_VER  #ifdef _MSC_VER
Line 344  static void sendmail(Request& r, const S Line 350  static void sendmail(Request& r, const S
         }          }
   
         if(!file_executable(*file_spec))          if(!file_executable(*file_spec))
                 throw Exception(0,                  throw Exception("email.send",
                         file_spec,                           file_spec, 
                         "is not executable."                          "is not executable."
 #ifdef PA_FORCED_SENDMAIL  #ifdef PA_FORCED_SENDMAIL
Line 369  static void sendmail(Request& r, const S Line 375  static void sendmail(Request& r, const S
                 &argv,                  &argv,
                 in, out, err);                  in, out, err);
         if(exit_status || err.size())          if(exit_status || err.size())
                 throw Exception(0,                  throw Exception("email.send",
                         &method_name,                          &method_name,
                         "'%s' reported problem: %s (%d)",                          "'%s' reported problem: %s (%d)",
                                 file_spec->cstr(),                                  file_spec->cstr(),
Line 413  void MMail::configure_user(Request& r) { Line 419  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, r.main_class, false))
                 if(Hash *mail_conf=mail_element->get_hash(0))                  if(Hash *mail_conf=mail_element->get_hash(0))
                         r.classes_conf.put(name(), mail_conf);                          r.classes_conf.put(name(), mail_conf);
                 else                  else

Removed from v.1.71  
changed lines
  Added in v.1.78


E-mail: