Changeset 2128


Ignore:
Timestamp:
Oct 9, 2007, 11:34:03 PM (17 years ago)
Author:
rub
Message:

Fix some little bugs on mail functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_7/include/functions_mail.inc.php

    r2125 r2128  
    2929// +-----------------------------------------------------------------------+
    3030
    31 
    32 /**
    33  * Encodes a string using Q form if required (RFC2045)
    34  * mail headers MUST contain only US-ASCII characters
    35  */
    36 function encode_mime_header($str)
    37 {
    38   $x = preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
    39   if ($x==0)
    40   {
    41     return $str;
    42   }
    43   // Replace every high ascii, control =, ? and _ characters
    44   $str = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
    45                   "'='.sprintf('%02X', ord('\\1'))", $str);
    46 
    47   // Replace every spaces to _ (more readable than =20)
    48   $str = str_replace(" ", "_", $str);
    49 
    50   global $lang_info;
    51   return '=?'.$lang_info['charset'].'?Q?'.$str.'?=';
    52 }
    53 
    5431/*
    5532 * Returns an array of mail configuration parameters :
     
    10481    $cvt_name = trim(preg_replace('#[\n\r]+#s', '', $name));
    10582    $cvt_email = trim(preg_replace('#[\n\r]+#s', '', $email));
    106 
    107     if ($cvt_name!="")
    108     {
    109       $cvt_name = encode_mime_header(
    110                 '"'
    111                 .addcslashes($cvt_name,'"')
    112                 .'"');
    113       $cvt_name .= ' ';
    114     }
     83    // Ascii convertion
     84    $cvt_name = '"'.addslashes(str_translate_to_ascii7bits($cvt_name)).'"';
    11585
    11686    if (strpos($cvt_email, '<') === false)
    11787    {
    118       return $cvt_name.'<'.$cvt_email.'>';
     88      return $cvt_name.' <'.$cvt_email.'>';
    11989    }
    12090    else
     
    143113
    144114  $res = array();
    145 
     115 
    146116  if (empty($args['template']) or empty($args['theme']))
    147117  {
     
    182152
    183153/**
    184  * Return string email format (html or not)
     154 * Return string email format (html or not) 
    185155 *
    186156 * @param string format
     
    191161}
    192162
    193 /*
     163/* 
    194164 * Switch language to param language
    195165 * All entries are push on language stack
     
    245215}
    246216
    247 /*
     217/* 
    248218 * Switch back language pushed with switch_lang_to function
    249219 *
     
    282252/*
    283253 * send en notification email to all administrators
    284  * if a administrator is doing action,
     254 * if a administrator is doing action, 
    285255 * he's be removed to email list
    286256 *
     
    345315        'Bcc' => $admins,
    346316        'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject),
    347         'content' =>
     317        'content' => 
    348318           l10n_args($keyargs_content)."\n\n"
    349319          .l10n_args($keyargs_content_admin_info)."\n",
     
    373343 */
    374344function pwg_mail_group(
    375   $group_id, $email_format, $keyargs_subject,
     345  $group_id, $email_format, $keyargs_subject, 
    376346  $dirname, $tpl_shortname,
    377347  $assign_vars = array(), $language_selected = '')
     
    383353SELECT
    384354  distinct language, template
    385 FROM
    386   '.USER_GROUP_TABLE.' as ug
     355FROM 
     356  '.USER_GROUP_TABLE.' as ug 
    387357  INNER JOIN '.USERS_TABLE.' as u  ON '.$conf['user_fields']['id'].' = ug.user_id
    388358  INNER JOIN '.USER_INFOS_TABLE.' as ui  ON ui.user_id = ug.user_id
    389 WHERE
     359WHERE 
    390360        '.$conf['user_fields']['email'].' IS NOT NULL
    391361    AND group_id = '.$group_id;
     
    411381      $list[] = $row;
    412382    }
    413   }
    414 
    415   foreach ($list as $elem)
    416   {
    417     $query = '
     383
     384    foreach ($list as $elem)
     385    {
     386      $query = '
    418387SELECT
    419388  u.'.$conf['user_fields']['username'].' as username,
    420389  u.'.$conf['user_fields']['email'].' as mail_address
    421 FROM
    422   '.USER_GROUP_TABLE.' as ug
     390FROM 
     391  '.USER_GROUP_TABLE.' as ug 
    423392  INNER JOIN '.USERS_TABLE.' as u  ON '.$conf['user_fields']['id'].' = ug.user_id
    424393  INNER JOIN '.USER_INFOS_TABLE.' as ui  ON ui.user_id = ug.user_id
    425 WHERE
     394WHERE 
    426395        '.$conf['user_fields']['email'].' IS NOT NULL
    427396    AND group_id = '.$group_id.'
     
    430399;';
    431400
    432     $result = pwg_query($query);
    433 
    434     if (mysql_num_rows($result) > 0)
    435     {
    436       $Bcc = array();
    437       while ($row = mysql_fetch_array($result))
     401      $result = pwg_query($query);
     402
     403      if (mysql_num_rows($result) > 0)
    438404      {
    439         if (!empty($row['mail_address']))
     405        $Bcc = array();
     406        while ($row = mysql_fetch_array($result))
    440407        {
    441           array_push($Bcc, format_email($row['username'], $row['mail_address']));
     408          if (!empty($row['mail_address']))
     409          {
     410            array_push($Bcc, format_email($row['username'], $row['mail_address']));
     411          }
    442412        }
    443       }
    444 
    445       if (count($Bcc) > 0)
    446       {
    447         switch_lang_to($elem['language']);
    448 
    449         $mail_template = get_mail_template($email_format, $elem);
    450         $mail_template->set_filename($tpl_shortname,
    451           (empty($dirname) ? '' : $dirname.'/').$tpl_shortname.'.tpl');
    452         $mail_template->assign_vars($assign_vars);
    453 
    454         $return = pwg_mail
    455         (
    456           '',
    457           array
     413
     414        if (count($Bcc) > 0)
     415        {
     416          switch_lang_to($elem['language']);
     417
     418          $mail_template = get_mail_template($email_format, $elem);
     419          $mail_template->set_filename($tpl_shortname,
     420            (empty($dirname) ? '' : $dirname.'/').$tpl_shortname.'.tpl');
     421          $mail_template->assign_vars($assign_vars);
     422
     423          $return = pwg_mail
    458424          (
    459             'Bcc' => $Bcc,
    460             'subject' => l10n_args($keyargs_subject),
    461             'email_format' => $email_format,
    462             'content' => $mail_template->parse($tpl_shortname, true),
    463             'content_format' => $email_format,
    464             'template' => $elem['template'],
    465             'theme' => $elem['theme']
    466           )
    467         ) and $return;
    468 
    469         switch_lang_back();
     425            '',
     426            array
     427            (
     428              'Bcc' => $Bcc,
     429              'subject' => l10n_args($keyargs_subject),
     430              'email_format' => $email_format,
     431              'content' => $mail_template->parse($tpl_shortname, true),
     432              'content_format' => $email_format,
     433              'template' => $elem['template'],
     434              'theme' => $elem['theme']
     435            )
     436          ) and $return;
     437
     438          switch_lang_back();
     439        }
    470440      }
    471441    }
     
    501471    return true;
    502472  }
    503 
     473 
    504474  if (!isset($conf_mail))
    505475  {
     
    539509  $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject']));
    540510  // Ascii convertion
    541   $cvt_subject = encode_mime_header($cvt_subject);
     511  $cvt_subject = str_translate_to_ascii7bits($cvt_subject);
    542512
    543513  if (!isset($args['content']))
     
    589559  $content = '';
    590560
    591   if (!isset($conf_mail[$args['email_format']][$lang_info['charset']][$args['template']][$args['theme']]))
     561  if (!isset($conf_mail[$args['email_format']][$lang_info['code']][$lang_info['charset']][$args['template']][$args['theme']]))
    592562  {
    593563    if (!isset($mail_template))
     
    607577        'LANG' => $lang_info['code'],
    608578        'DIR' => $lang_info['direction'],
    609 
     579       
    610580        // Footer
    611581        'GALLERY_URL' =>
     
    651621    // what are displayed on the header of each mail ?
    652622    $conf_mail[$args['email_format']]
    653       [$lang_info['charset']]
     623      [$lang_info['code']][$lang_info['charset']]
    654624      [$args['template']][$args['theme']]['header'] =
    655625        $mail_template->parse('mail_header', true);
     
    657627    // what are displayed on the footer of each mail ?
    658628    $conf_mail[$args['email_format']]
    659       [$lang_info['charset']]
     629      [$lang_info['code']][$lang_info['charset']]
    660630      [$args['template']][$args['theme']]['footer'] =
    661631        $mail_template->parse('mail_footer', true);
     
    664634  // Header
    665635  $content.= $conf_mail[$args['email_format']]
    666               [$lang_info['charset']]
     636              [$lang_info['code']][$lang_info['charset']]
    667637              [$args['template']][$args['theme']]['header'];
    668638
     
    684654  // Footer
    685655  $content.= $conf_mail[$args['email_format']]
    686               [$lang_info['charset']]
     656              [$lang_info['code']][$lang_info['charset']]
    687657              [$args['template']][$args['theme']]['footer'];
    688658
     
    700670    global $user;
    701671    @mkdir(PHPWG_ROOT_PATH.'testmail');
    702     $filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username'];
     672    $filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username'].$cvt_subject;
    703673    if ($args['content_format'] == 'text/plain')
    704674    {
Note: See TracChangeset for help on using the changeset viewer.