Changeset 938 in subversion


Ignore:
Timestamp:
Dec 10, 2007 10:27:19 AM (5 years ago)
Author:
thomasb
Message:

New class rcube_user + send message disposition notification

Location:
trunk/roundcubemail
Files:
2 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/.htaccess

    r801 r938  
    88  php_value     upload_max_filesize     5M 
    99  php_value     post_max_size   6M 
     10  php_value memory_limit        64M 
    1011</IfModule> 
    1112 
     
    1617  php_value     upload_max_filesize     5M 
    1718  php_value     post_max_size   6M 
     19  php_value memory_limit        64M 
    1820</IfModule> 
    1921 
  • trunk/roundcubemail/CHANGELOG

    r936 r938  
    11CHANGELOG RoundCube Webmail 
    22--------------------------- 
     3 
     42007/12/10 (thomasb) 
     5---------- 
     6- Delegate user-stuff to new class rcube_user 
     7- Implement Message-Disposition-Notification (Receipts) 
    38 
    492007/12/05 (tomekp) 
  • trunk/roundcubemail/index.php

    r882 r938  
    33 +-----------------------------------------------------------------------+ 
    44 | RoundCube Webmail IMAP Client                                         | 
    5  | Version 0.1-20071017                                                  | 
     5 | Version 0.1-20071210                                                  | 
    66 |                                                                       | 
    77 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 | 
     
    4242 
    4343// application constants 
    44 define('RCMAIL_VERSION', '0.1-20071017'); 
     44define('RCMAIL_VERSION', '0.1-20071210'); 
    4545define('RCMAIL_CHARSET', 'UTF-8'); 
    4646define('JS_OBJECT_NAME', 'rcmail'); 
     
    197197 
    198198// log in to imap server 
    199 if (!empty($_SESSION['user_id']) && $_task=='mail') 
     199if (!empty($USER->ID) && $_task=='mail') 
    200200{ 
    201201  $conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl']); 
     
    211211 
    212212// not logged in -> set task to 'login 
    213 if (empty($_SESSION['user_id'])) 
     213if (empty($USER->ID)) 
    214214{ 
    215215  if ($OUTPUT->ajax_call) 
     
    239239 
    240240// not logged in -> show login page 
    241 if (!$_SESSION['user_id']) 
     241if (empty($USER->ID)) 
    242242{ 
    243243  $OUTPUT->task = 'login'; 
     
    274274  if ($_action=='viewsource') 
    275275    include('program/steps/mail/viewsource.inc'); 
     276 
     277  if ($_action=='sendmdn') 
     278    include('program/steps/mail/sendmdn.inc'); 
    276279 
    277280  if ($_action=='send') 
  • trunk/roundcubemail/program/include/main.inc

    r931 r938  
    3030require_once('lib/utf7.inc'); 
    3131require_once('lib/utf8.class.php'); 
     32require_once('include/rcube_user.inc'); 
    3233require_once('include/rcube_shared.inc'); 
    3334require_once('include/rcmail_template.inc'); 
     
    4950  { 
    5051  global $sess_id, $sess_user_lang; 
    51   global $CONFIG, $INSTALL_PATH, $BROWSER, $OUTPUT, $_SESSION, $IMAP, $DB; 
     52  global $CONFIG, $INSTALL_PATH, $BROWSER, $OUTPUT, $_SESSION, $IMAP, $DB, $USER; 
    5253 
    5354  // check client 
     
    8889  $sess_user_lang = rcube_language_prop($_SESSION['user_lang']); 
    8990 
     91  // create user object 
     92  $USER = new rcube_user($_SESSION['user_id']); 
    9093 
    9194  // overwrite config with user preferences 
     
    322325function rcmail_kill_session() 
    323326  { 
    324   // save user preferences 
    325   $a_user_prefs = $_SESSION['user_prefs']; 
    326   if (!is_array($a_user_prefs)) 
    327     $a_user_prefs = array(); 
    328      
     327  global $USER; 
     328   
    329329  if ((isset($_SESSION['sort_col']) && $_SESSION['sort_col']!=$a_user_prefs['message_sort_col']) || 
    330330      (isset($_SESSION['sort_order']) && $_SESSION['sort_order']!=$a_user_prefs['message_sort_order'])) 
    331331    { 
    332     $a_user_prefs['message_sort_col'] = $_SESSION['sort_col']; 
    333     $a_user_prefs['message_sort_order'] = $_SESSION['sort_order']; 
    334     rcmail_save_user_prefs($a_user_prefs); 
     332    $a_user_prefs = array('message_sort_col' => $_SESSION['sort_col'], 'message_sort_order' => $_SESSION['sort_order']); 
     333    $USER->save_prefs($a_user_prefs); 
    335334    } 
    336335 
    337336  $_SESSION = array('user_lang' => $GLOBALS['sess_user_lang'], 'auth_time' => time(), 'temp' => true); 
    338337  setcookie('sessauth', '-del-', time()-60); 
     338  $USER->reset(); 
    339339  } 
    340340 
     
    532532function rcmail_login($user, $pass, $host=NULL) 
    533533  { 
    534   global $CONFIG, $IMAP, $DB, $sess_user_lang; 
     534  global $CONFIG, $IMAP, $DB, $USER, $sess_user_lang; 
    535535  $user_id = NULL; 
    536536   
     
    584584  // try to resolve email address from virtuser table     
    585585  if (!empty($CONFIG['virtuser_file']) && strpos($user, '@')) 
    586     $user = rcmail_email2user($user); 
     586    $user = rcube_user::email2user($user); 
    587587 
    588588  // lowercase username if it's an e-mail address (#1484473) 
     
    591591 
    592592  // query if user already registered 
    593   $sql_result = $DB->query( 
    594     "SELECT user_id, username, language, preferences 
    595      FROM ".get_table_name('users')." 
    596      WHERE  mail_host=? AND (username=? OR alias=?)", 
    597     $host, 
    598     $user, 
    599     $user); 
     593  if ($existing = rcube_user::query($user, $host)) 
     594  $USER = $existing; 
    600595 
    601596  // user already registered -> overwrite username 
    602   if ($sql_arr = $DB->fetch_assoc($sql_result)) 
    603     { 
    604     $user_id = $sql_arr['user_id']; 
    605     $user = $sql_arr['username']; 
     597  if ($USER->ID) 
     598    { 
     599    $user_id = $USER->ID; 
     600    $user = $USER->data['username']; 
    606601    } 
    607602 
    608603  // exit if IMAP login failed 
    609604  if (!($imap_login  = $IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl))) 
    610     return FALSE; 
     605    return false; 
    611606 
    612607  // user already registered 
    613   if ($user_id && !empty($sql_arr)) 
     608  if ($USER->ID) 
    614609    { 
    615610    // get user prefs 
    616     if (strlen($sql_arr['preferences'])) 
    617       { 
    618       $user_prefs = unserialize($sql_arr['preferences']); 
    619       $_SESSION['user_prefs'] = $user_prefs; 
    620       array_merge($CONFIG, $user_prefs); 
    621       } 
    622  
     611    $_SESSION['user_prefs'] = $USER->get_prefs(); 
     612    array_merge($CONFIG, $_SESSION['user_prefs']); 
    623613 
    624614    // set user specific language 
    625     if (strlen($sql_arr['language'])) 
    626       $sess_user_lang = $_SESSION['user_lang'] = $sql_arr['language']; 
     615    if (!empty($USER->data['language'])) 
     616      $sess_user_lang = $_SESSION['user_lang'] = $USER->data['language']; 
    627617       
    628618    // update user's record 
    629     $DB->query("UPDATE ".get_table_name('users')." 
    630                 SET    last_login=".$DB->now()." 
    631                 WHERE  user_id=?", 
    632                 $user_id); 
     619    $USER->touch(); 
    633620    } 
    634621  // create new system user 
    635622  else if ($CONFIG['auto_create_user']) 
    636623    { 
    637     $user_id = rcmail_create_user($user, $host); 
     624    if ($created = rcube_user::create($user, $host)) 
     625    { 
     626      $USER = $created; 
     627       
     628      // get existing mailboxes 
     629      $a_mailboxes = $IMAP->list_mailboxes(); 
     630    } 
    638631    } 
    639632  else 
     
    647640    } 
    648641 
    649   if ($user_id) 
    650     { 
    651     $_SESSION['user_id']   = $user_id; 
     642  if ($USER->ID) 
     643    { 
     644    $_SESSION['user_id']   = $USER->ID; 
     645    $_SESSION['username']  = $USER->data['username']; 
    652646    $_SESSION['imap_host'] = $host; 
    653647    $_SESSION['imap_port'] = $imap_port; 
    654648    $_SESSION['imap_ssl']  = $imap_ssl; 
    655     $_SESSION['username']  = $user; 
    656649    $_SESSION['user_lang'] = $sess_user_lang; 
    657650    $_SESSION['password']  = encrypt_passwd($pass); 
     
    670663  return FALSE; 
    671664  } 
    672  
    673  
    674 /** 
    675  * Create new entry in users and identities table 
    676  * 
    677  * @param string User name 
    678  * @param string IMAP host 
    679  * @return mixed New user ID or False on failure 
    680  */ 
    681 function rcmail_create_user($user, $host) 
    682 { 
    683   global $DB, $CONFIG, $IMAP; 
    684  
    685   $user_email = ''; 
    686  
    687   // try to resolve user in virtusertable 
    688   if (!empty($CONFIG['virtuser_file']) && !strpos($user, '@')) 
    689     $user_email = rcmail_user2email($user); 
    690  
    691   $DB->query("INSERT INTO ".get_table_name('users')." 
    692               (created, last_login, username, mail_host, alias, language) 
    693               VALUES (".$DB->now().", ".$DB->now().", ?, ?, ?, ?)", 
    694               strip_newlines($user), 
    695               strip_newlines($host), 
    696               strip_newlines($user_email), 
    697               $_SESSION['user_lang']); 
    698  
    699   if ($user_id = $DB->insert_id(get_sequence_name('users'))) 
    700   { 
    701     $mail_domain = rcmail_mail_domain($host); 
    702     
    703     if ($user_email=='') 
    704       $user_email = strpos($user, '@') ? $user : sprintf('%s@%s', $user, $mail_domain); 
    705  
    706     $user_name = $user!=$user_email ? $user : ''; 
    707  
    708     // try to resolve the e-mail address from the virtuser table 
    709     if (!empty($CONFIG['virtuser_query']) && 
    710         ($sql_result = $DB->query(preg_replace('/%u/', $DB->escapeSimple($user), $CONFIG['virtuser_query']))) && 
    711         ($DB->num_rows()>0)) 
    712     { 
    713       while ($sql_arr = $DB->fetch_array($sql_result)) 
    714       { 
    715         $DB->query("INSERT INTO ".get_table_name('identities')." 
    716                    (user_id, del, standard, name, email) 
    717                    VALUES (?, 0, 1, ?, ?)", 
    718                    $user_id, 
    719                    strip_newlines($user_name), 
    720                    preg_replace('/^@/', $user . '@', $sql_arr[0])); 
    721       } 
    722     } 
    723     else 
    724     { 
    725       // also create new identity records 
    726       $DB->query("INSERT INTO ".get_table_name('identities')." 
    727                   (user_id, del, standard, name, email) 
    728                   VALUES (?, 0, 1, ?, ?)", 
    729                   $user_id, 
    730                   strip_newlines($user_name), 
    731                   strip_newlines($user_email)); 
    732     } 
    733                         
    734     // get existing mailboxes 
    735     $a_mailboxes = $IMAP->list_mailboxes(); 
    736   } 
    737   else 
    738   { 
    739     raise_error(array( 
    740       'code' => 500, 
    741       'type' => 'php', 
    742       'line' => __LINE__, 
    743       'file' => __FILE__, 
    744       'message' => "Failed to create new user"), TRUE, FALSE); 
    745   } 
    746      
    747   return $user_id; 
    748 } 
    749665 
    750666 
     
    791707 
    792708  return $result; 
    793   } 
    794  
    795  
    796 /** 
    797  * Resolve username using a virtuser table 
    798  * 
    799  * @param string E-mail address to resolve 
    800  * @return string Resolved IMAP username 
    801  */ 
    802 function rcmail_email2user($email) 
    803   { 
    804   $user = $email; 
    805   $r = rcmail_findinvirtual("^$email"); 
    806  
    807   for ($i=0; $i<count($r); $i++) 
    808     { 
    809     $data = $r[$i]; 
    810     $arr = preg_split('/\s+/', $data); 
    811     if(count($arr)>0) 
    812       { 
    813       $user = trim($arr[count($arr)-1]); 
    814       break; 
    815       } 
    816     } 
    817  
    818   return $user; 
    819   } 
    820  
    821  
    822 /** 
    823  * Resolve e-mail address from virtuser table 
    824  * 
    825  * @param string User name 
    826  * @return string Resolved e-mail address 
    827  */ 
    828 function rcmail_user2email($user) 
    829   { 
    830   $email = ""; 
    831   $r = rcmail_findinvirtual("$user$"); 
    832  
    833   for ($i=0; $i<count($r); $i++) 
    834     { 
    835     $data=$r[$i]; 
    836     $arr = preg_split('/\s+/', $data); 
    837     if (count($arr)>0) 
    838       { 
    839       $email = trim($arr[0]); 
    840       break; 
    841       } 
    842     } 
    843  
    844   return $email; 
    845   }  
    846  
    847  
    848 /** 
    849  * Write the given user prefs to the user's record 
    850  * 
    851  * @param mixed User prefs to save 
    852  * @return boolean True on success, False on failure 
    853  */ 
    854 function rcmail_save_user_prefs($a_user_prefs) 
    855   { 
    856   global $DB, $CONFIG, $sess_user_lang; 
    857    
    858   // merge (partial) prefs array with existing settings 
    859   $a_user_prefs += (array)$_SESSION['user_prefs']; 
    860    
    861   $DB->query("UPDATE ".get_table_name('users')." 
    862               SET    preferences=?, 
    863                      language=? 
    864               WHERE  user_id=?", 
    865               serialize($a_user_prefs), 
    866               $sess_user_lang, 
    867               $_SESSION['user_id']); 
    868  
    869   if ($DB->affected_rows()) 
    870     { 
    871     $_SESSION['user_prefs'] = $a_user_prefs;   
    872     $CONFIG = array_merge($CONFIG, $a_user_prefs); 
    873     return TRUE; 
    874     } 
    875      
    876   return FALSE; 
    877709  } 
    878710 
     
    15141346  return $styles; 
    15151347  } 
     1348 
     1349/** 
     1350 * Try to autodetect operating system and find the correct line endings 
     1351 * 
     1352 * @return string The appropriate mail header delimiter 
     1353 */ 
     1354function rcmail_header_delm() 
     1355{ 
     1356  global $CONFIG; 
     1357   
     1358  // use the configured delimiter for headers 
     1359  if (!empty($CONFIG['mail_header_delimiter'])) 
     1360    return $CONFIG['mail_header_delimiter']; 
     1361  else if (strtolower(substr(PHP_OS, 0, 3)=='win'))  
     1362    return "\r\n"; 
     1363  else if (strtolower(substr(PHP_OS, 0, 3)=='mac')) 
     1364    return "\r\n"; 
     1365  else     
     1366    return "\n"; 
     1367} 
    15161368 
    15171369 
  • trunk/roundcubemail/program/include/rcmail_template.inc

    r930 r938  
    762762function rcmail_current_username($attrib) 
    763763  { 
    764   global $DB; 
     764  global $USER; 
    765765  static $s_username; 
    766766 
     
    769769    return $s_username; 
    770770 
    771   // get e-mail address form default identity 
    772   $sql_result = $DB->query( 
    773     "SELECT email AS mailto 
    774      FROM ".get_table_name('identities')." 
    775      WHERE  user_id=? 
    776      AND    standard=1 
    777      AND    del<>1", 
    778     $_SESSION['user_id']); 
    779                                     
    780   if ($DB->num_rows($sql_result)) 
    781     { 
    782     $sql_arr = $DB->fetch_assoc($sql_result); 
    783     $s_username = $sql_arr['mailto']; 
    784     } 
     771  if ($sql_arr = $USER->get_identity()) 
     772    $s_username = $sql_arr['email']; 
    785773  else if (strstr($_SESSION['username'], '@')) 
    786774    $s_username = $_SESSION['username']; 
  • trunk/roundcubemail/program/js/app.js

    r934 r938  
    223223          this.gui_objects.folderlist = this.gui_objects.mailboxlist; 
    224224          this.http_request('getunread', ''); 
     225        } 
     226         
     227        // ask user to send MDN 
     228        if (this.env.mdn_request && this.env.uid) 
     229        { 
     230          var mdnurl = '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox); 
     231          if (confirm(this.get_label('mdnrequest'))) 
     232            this.http_post('sendmdn', mdnurl); 
     233          else 
     234            this.http_post('mark', mdnurl+'&_flag=mdnsent'); 
    225235        } 
    226236 
  • trunk/roundcubemail/program/lib/imap.inc

    r933 r938  
    12561256                        $result[$id]->id = $id; 
    12571257                        $result[$id]->subject = ""; 
     1258                        $result[$id]->messageID = "mid:".$id; 
    12581259                        /* 
    12591260                                Start parsing headers.  The problem is, some header "lines" take up multiple lines. 
     
    12941295 
    12951296                        //      create array with header field:data 
    1296                         $headers = array(); 
    12971297                        while ( list($lines_key, $str) = each($lines) ){ 
    12981298                                list($field, $string) = iil_SplitHeaderLine($str); 
    12991299                                $field = strtolower($field); 
    1300                                 $headers[$field] = $string; 
     1300                                 
     1301                                switch ($field){ 
     1302                                        case 'date'; 
     1303                                                $result[$id]->date = $string; 
     1304                                                $result[$id]->timestamp = iil_StrToTime($string); 
     1305                                                break; 
     1306                                        case 'from': 
     1307                                                $result[$id]->from = $string; 
     1308                                                break; 
     1309                                        case 'to': 
     1310                                                $result[$id]->to = str_replace("\n", " ", $string); 
     1311                                                break; 
     1312                                        case 'subject': 
     1313                                                $result[$id]->subject = str_replace("\n", "", $string); 
     1314                                                break; 
     1315                                        case 'reply-to': 
     1316                                                $result[$id]->replyto = str_replace("\n", " ", $string); 
     1317                                                break; 
     1318                                        case 'cc': 
     1319                                                $result[$id]->cc = str_replace("\n", " ", $string); 
     1320                                                break; 
     1321                                        case 'bcc': 
     1322                                                $result[$id]->bcc = str_replace("\n", " ", $string); 
     1323                                                break; 
     1324                                        case 'content-transfer-encoding': 
     1325                                                $result[$id]->encoding = str_replace("\n", " ", $string); 
     1326                                                break; 
     1327                                        case 'content-type': 
     1328                                                $ctype_parts = explode(";", $string); 
     1329                                                $result[$id]->ctype = array_shift($ctype_parts); 
     1330                                                foreach ($ctype_parts as $ctype_add) 
     1331                                                        if (preg_match('/charset="?([a-z0-9\-]+)"?/i', $ctype_add, $regs)) 
     1332                                                                $result[$id]->charset = $regs[1]; 
     1333                                                break; 
     1334                                        case 'in-reply-to': 
     1335                                                $result[$id]->in_reply_to = ereg_replace("[\n<>]", '', $string); 
     1336                                                break; 
     1337                                        case 'references': 
     1338                                                $result[$id]->references = $string; 
     1339                                                break; 
     1340                                                case 'return-receipt-to': 
     1341                                                case 'disposition-notification-to': 
     1342                                                case 'x-confirm-reading-to': 
     1343                                                        $result[$id]->mdn_to = str_replace("\n", " ", $string); 
     1344                                                        break; 
     1345                                        case 'message-id': 
     1346                                                $result[$id]->messageID = $string; 
     1347                                                break; 
     1348                                } 
    13011349                        } 
    1302                         $result[$id]->date = $headers["date"]; 
    1303                         $result[$id]->timestamp = iil_StrToTime($headers["date"]); 
    1304                         $result[$id]->from = $headers["from"]; 
    1305                         $result[$id]->to = str_replace("\n", " ", $headers["to"]); 
    1306                         $result[$id]->subject = str_replace("\n", "", $headers["subject"]); 
    1307                         $result[$id]->replyto = str_replace("\n", " ", $headers["reply-to"]); 
    1308                         $result[$id]->cc = str_replace("\n", " ", $headers["cc"]); 
    1309                         $result[$id]->bcc = str_replace("\n", " ", $headers["bcc"]); 
    1310                         $result[$id]->encoding = str_replace("\n", " ", $headers["content-transfer-encoding"]); 
    1311                         $result[$id]->ctype = str_replace("\n", " ", $headers["content-type"]); 
    1312                         $result[$id]->in_reply_to = ereg_replace("[\n<>]",'', $headers['in-reply-to']); 
    1313                         $result[$id]->references = $headers["references"]; 
    1314                         $result[$id]->mdn_to = $headers["disposition-notification-to"]; 
    1315                          
    1316                         list($result[$id]->ctype, $ctype_add) = explode(";", $headers["content-type"]); 
    1317  
    1318                         if (preg_match('/charset="?([a-z0-9\-]+)"?/i', $ctype_add, $regs)) 
    1319                                 $result[$id]->charset = $regs[1]; 
    1320  
    1321                         $messageID = $headers["message-id"]; 
    1322                         if (!$messageID) "mid:".$id; 
    1323                         $result[$id]->messageID = $messageID; 
    1324                         } 
    1325             else { 
    1326             $a=explode(" ", $line); 
    1327             }  
     1350                } 
     1351                else { 
     1352                        $a=explode(" ", $line); 
     1353                } 
    13281354                         
    13291355                } 
  • trunk/roundcubemail/program/lib/rc_mail_mime.inc

    r514 r938  
    2626class rc_mail_mime extends Mail_mime 
    2727{ 
     28  /** 
     29   * Set build parameters 
     30   */ 
     31  function setParam($param) 
     32  { 
     33    if (is_array($param)) 
     34      $this->_build_params = array_merge($this->_build_params, $param); 
     35  } 
    2836   
    2937  /** 
     
    6472    return true; 
    6573  } 
    66  
     74   
    6775   
    6876  /** 
     
    7482  { 
    7583     return $this->_htmlbody; 
     84  } 
     85   
     86   
     87  /** 
     88   * Creates a new mimePart object, using multipart/mixed as 
     89   * the initial content-type and returns it during the 
     90   * build process. 
     91   * 
     92   * @return object  The multipart/mixed mimePart object 
     93   * @access private 
     94   */ 
     95  function &_addMixedPart() 
     96  { 
     97    $params['content_type'] = $this->_headers['Content-Type'] ? $this->_headers['Content-Type'] : 'multipart/mixed'; 
     98    $ret = new Mail_mimePart('', $params); 
     99    return $ret; 
    76100  } 
    77101   
     
    139163        // add chunk to output string by regarding the header maxlen 
    140164        $len = strlen($value); 
    141         if ($line_len + $len < $maxlen) 
     165        if ($i == 0 || $line_len + $len < $maxlen) 
    142166        { 
    143167          $hdr_value .= ($i>0?', ':'') . $value; 
  • trunk/roundcubemail/program/localization/en_US/labels.inc

    r842 r938  
    161161$labels['addreplyto'] = 'Add Reply-To'; 
    162162 
     163// mdn 
     164$labels['mdnrequest'] = 'The sender of this message has asked to be notified when you read this message. Do you wish to notify the sender?'; 
     165$labels['receiptread'] = 'Return Receipt (read)'; 
     166$labels['yourmessage'] = 'This is a Return Receipt for your message'; 
     167$labels['receiptnote'] = 'Note: This receipt only acknowledges that the message was displayed on the recipient\'s computer. There is no guarantee that the recipient has read or understood the message contents.'; 
    163168 
    164169// address boook 
  • trunk/roundcubemail/program/localization/en_US/messages.inc

    r842 r938  
    7575$messages['errorsavingcontact'] = 'Could not save the contact address'; 
    7676$messages['movingmessage'] = 'Moving message...'; 
     77$messages['receiptsent'] = 'Successfully send the receipt message'; 
     78$messages['errorsendingreceipt'] = 'Could not send the receipt'; 
    7779 
    7880?> 
  • trunk/roundcubemail/program/steps/mail/compose.inc

    r911 r938  
    231231function rcmail_compose_header_from($attrib) 
    232232  { 
    233   global $IMAP, $MESSAGE, $DB, $OUTPUT, $compose_mode; 
     233  global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $compose_mode; 
    234234     
    235235  // pass the following attributes to the form class 
     
    264264 
    265265  // get this user's identities 
    266   $sql_result = $DB->query("SELECT identity_id, name, email, signature, html_signature 
    267                             FROM   ".get_table_name('identities')." 
    268                             WHERE user_id=? 
    269                             AND    del<>1 
    270                             ORDER BY ".$DB->quoteIdentifier('standard')." DESC, name ASC", 
    271                            $_SESSION['user_id']); 
     266  $sql_result = $USER->list_identities(); 
    272267 
    273268  if ($DB->num_rows($sql_result)) 
     
    870865require_once('include/rcube_contacts.inc'); 
    871866 
    872 $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']); 
     867$CONTACTS = new rcube_contacts($DB, $USER->ID); 
    873868$CONTACTS->set_pagesize(1000); 
    874869                                    
  • trunk/roundcubemail/program/steps/mail/func.inc

    r931 r938  
    2222require_once('lib/html2text.inc'); 
    2323require_once('lib/enriched.inc'); 
     24require_once('include/rcube_smtp.inc'); 
    2425 
    2526 
     
    726727      // part text/[plain|html] OR message/delivery-status 
    727728      else if (($primary_type=='text' && ($secondary_type=='plain' || $secondary_type=='html') && $mail_part->disposition!='attachment') || 
    728                ($primary_type=='message' && $secondary_type=='delivery-status')) 
     729               ($primary_type=='message' && ($secondary_type=='delivery-status' || $secondary_type=='disposition-notification'))) 
    729730        { 
    730731        $mail_part->type = 'content'; 
     
    759760          { 
    760761          if (!$mail_part->filename) 
    761             $mail_part->filename = 'file_'.$mail_part->mime_id; 
     762            $mail_part->filename = 'Part '.$mail_part->mime_id; 
    762763          $a_attachments[] = $mail_part; 
    763764          } 
     
    12511252  unset($_SESSION['compose']); 
    12521253  } 
     1254   
     1255 
     1256/** 
     1257 * Send the given message compose object using the configured method 
     1258 */ 
     1259function rcmail_deliver_message(&$message, $from, $mailto) 
     1260{ 
     1261  global $CONFIG; 
     1262 
     1263  $headers = $message->headers(); 
     1264  $msg_body = $message->get(); 
     1265   
     1266  // send thru SMTP server using custom SMTP library 
     1267  if ($CONFIG['smtp_server']) 
     1268    { 
     1269    // generate list of recipients 
     1270    $a_recipients = array($mailto); 
     1271   
     1272    if (strlen($headers['Cc'])) 
     1273      $a_recipients[] = $headers['Cc']; 
     1274    if (strlen($headers['Bcc'])) 
     1275      $a_recipients[] = $headers['Bcc']; 
     1276   
     1277    // clean Bcc from header for recipients 
     1278    $send_headers = $headers; 
     1279    unset($send_headers['Bcc']); 
     1280 
     1281    // send message 
     1282    $smtp_response = array(); 
     1283    $sent = smtp_mail($from, $a_recipients, ($foo = $message->txtHeaders($send_headers)), $msg_body, $smtp_response); 
     1284 
     1285    // log error 
     1286    if (!$sent) 
     1287      raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__, 
     1288                        'message' => "SMTP error: ".join("\n", $smtp_response)), TRUE, FALSE); 
     1289    } 
     1290   
     1291  // send mail using PHP's mail() function 
     1292  else 
     1293    { 
     1294    // unset some headers because they will be added by the mail() function 
     1295    $headers_enc = $message->headers($headers); 
     1296    $headers_php = $message->_headers; 
     1297    unset($headers_php['To'], $headers_php['Subject']); 
     1298     
     1299    // reset stored headers and overwrite 
     1300    $message->_headers = array(); 
     1301    $header_str = $message->txtHeaders($headers_php); 
     1302   
     1303    if (ini_get('safe_mode')) 
     1304      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str); 
     1305    else 
     1306      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from"); 
     1307    } 
     1308   
     1309   
     1310  $message->_headers = array(); 
     1311  $message->headers($headers); 
     1312   
     1313  return $sent; 
     1314} 
    12531315 
    12541316 
  • trunk/roundcubemail/program/steps/mail/sendmail.inc

    r930 r938  
    2323 
    2424//require_once('lib/smtp.inc'); 
    25 require_once('include/rcube_smtp.inc'); 
    2625require_once('lib/html2text.inc'); 
    2726require_once('lib/rc_mail_mime.inc'); 
     
    3837 
    3938 
     39// get identity record 
    4040function rcmail_get_identity($id) 
    4141  { 
    42   global $DB, $OUTPUT; 
    43    
    44   // get identity record 
    45   $sql_result = $DB->query("SELECT *, email AS mailto 
    46                             FROM ".get_table_name('identities')." 
    47                             WHERE  identity_id=? 
    48                             AND    user_id=? 
    49                             AND    del<>1", 
    50                             $id,$_SESSION['user_id']); 
    51                                     
    52   if ($DB->num_rows($sql_result)) 
    53     { 
    54     $sql_arr = $DB->fetch_assoc($sql_result); 
     42  global $USER, $OUTPUT; 
     43   
     44  if ($sql_arr = $USER->get_identity($id)) 
     45    { 
    5546    $out = $sql_arr; 
     47    $out['mailto'] = $sql_arr['email']; 
    5648    $name = strpos($sql_arr['name'], ",") ? '"'.$sql_arr['name'].'"' : $sql_arr['name']; 
    5749    $out['string'] = sprintf('%s <%s>', 
    5850                             rcube_charset_convert($name, RCMAIL_CHARSET, $OUTPUT->get_charset()), 
    59                              $sql_arr['mailto']); 
     51                             $sql_arr['email']); 
    6052    return $out; 
    6153    } 
     
    167159 
    168160// compose headers array 
    169 $headers = array('Date' => date('D, j M Y H:i:s O'), 
     161$headers = array('Date' => date('r'), 
    170162                 'From' => rcube_charset_convert($identity_arr['string'], RCMAIL_CHARSET, $message_charset), 
    171163                 'To'   => $mailto); 
     
    226218  $message_body .= "\r\n" . rcube_charset_convert($footer, 'UTF-8', $message_charset); 
    227219 
    228 // try to autodetect operating system and use the correct line endings 
    229 // use the configured delimiter for headers 
    230 if (!empty($CONFIG['mail_header_delimiter'])) 
    231   $header_delm = $CONFIG['mail_header_delimiter']; 
    232 else if (strtolower(substr(PHP_OS, 0, 3)=='win'))  
    233   $header_delm = "\r\n"; 
    234 else if (strtolower(substr(PHP_OS, 0, 3)=='mac')) 
    235   $header_delm = "\r\n"; 
    236 else     
    237   $header_delm = "\n"; 
    238  
    239  
    240220$isHtmlVal = strtolower(get_input_value('_is_html', RCUBE_INPUT_POST)); 
    241221$isHtml = ($isHtmlVal == "1"); 
    242222 
    243223// create extended PEAR::Mail_mime instance 
    244 $MAIL_MIME = new rc_mail_mime($header_delm); 
     224$MAIL_MIME = new rc_mail_mime(rcmail_header_delm()); 
    245225 
    246226// For HTML-formatted messages, construct the MIME message with both 
     
    283263 
    284264// encoding settings for mail composing 
    285 $message_param = array( 
     265$MAIL_MIME->setParam(array( 
    286266  'text_encoding' => $transfer_encoding, 
    287267  'html_encoding' => 'quoted-printable', 
     
    290270  'html_charset'  => $message_charset, 
    291271  'text_charset'  => $message_charset, 
    292 ); 
    293  
    294 // compose message body and get headers 
    295 $msg_body = $MAIL_MIME->get($message_param); 
    296 // unset to save memory. 
    297 unset($MAIL_MIME->_parts); 
     272)); 
    298273 
    299274// encoding subject header with mb_encode provides better results with asian characters 
     
    301276{ 
    302277  mb_internal_encoding($message_charset); 
    303   $mb_subject = mb_encode_mimeheader($headers['Subject'], $message_charset, 'Q'); 
     278  $headers['Subject'] = mb_encode_mimeheader($headers['Subject'], $message_charset, 'Q'); 
    304279  mb_internal_encoding(RCMAIL_CHARSET); 
    305280} 
    306281 
     282// pass headers to message object 
     283$MAIL_MIME->headers($headers); 
     284 
    307285// Begin SMTP Delivery Block  
    308 if (!$savedraft) { 
    309  
    310   // send thru SMTP server using custom SMTP library 
    311   if ($CONFIG['smtp_server']) 
    312     { 
    313     // generate list of recipients 
    314     $a_recipients = array($mailto); 
    315    
    316     if (strlen($headers['Cc'])) 
    317       $a_recipients[] = $headers['Cc']; 
    318     if (strlen($headers['Bcc'])) 
    319       $a_recipients[] = $headers['Bcc']; 
    320    
    321     // clean Bcc from header for recipients 
    322     $send_headers = $headers; 
    323     unset($send_headers['Bcc']); 
    324    
    325     if (!empty($mb_subject)) 
    326       $send_headers['Subject'] = $mb_subject; 
    327    
    328     // send message 
    329     $smtp_response = array(); 
    330     $sent = smtp_mail($from, $a_recipients, ($foo = $MAIL_MIME->txtHeaders($send_headers)), $msg_body, $smtp_response); 
    331    
    332     // log error 
    333     if (!$sent) 
    334       raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__, 
    335                         'message' => "SMTP error: ".join("\n", $smtp_response)), TRUE, FALSE); 
    336     } 
    337    
    338   // send mail using PHP's mail() function 
    339   else 
    340     { 
    341     // unset some headers because they will be added by the mail() function 
    342     $headers_enc = $MAIL_MIME->headers($headers); 
    343     $headers_php = $MAIL_MIME->_headers; 
    344     unset($headers_php['To'], $headers_php['Subject']); 
    345      
    346     if (!empty($mb_subject)) 
    347       $headers_enc['Subject'] = $mb_subject; 
    348      
    349     // reset stored headers and overwrite 
    350     $MAIL_MIME->_headers = array(); 
    351     $header_str = $MAIL_MIME->txtHeaders($headers_php); 
    352    
    353     if (ini_get('safe_mode')) 
    354       $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str); 
    355     else 
    356       $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from"); 
    357     } 
    358    
     286if (!$savedraft) 
     287{ 
     288  $sent = rcmail_deliver_message($MAIL_MIME, $from, $mailto); 
    359289   
    360290  // return to compose page if sending failed 
     
    365295    return; 
    366296    } 
    367    
    368297   
    369298  // set repliead flag 
     
    383312if ($CONFIG[$store_target]) 
    384313  { 
    385   // create string of complete message headers 
    386   $header_str = $MAIL_MIME->txtHeaders($headers); 
    387  
    388314  // check if mailbox exists 
    389315  if (!in_array_nocase($CONFIG[$store_target], $IMAP->list_mailboxes())) 
     
    392318    $store_folder = TRUE; 
    393319   
    394   // add headers to message body 
    395   $msg_body = $header_str."\r\n".$msg_body; 
    396  
    397320  // append message to sent box 
    398321  if ($store_folder) 
    399     $saved = $IMAP->save_message($CONFIG[$store_target], $msg_body); 
     322    $saved = $IMAP->save_message($CONFIG[$store_target], $MAIL_MIME->getMessage()); 
    400323 
    401324  // raise error if saving failed 
  • trunk/roundcubemail/program/steps/mail/show.inc

    r933 r938  
    7676  // check for unset disposition notification 
    7777  if ($MESSAGE['headers']->mdn_to && !$MESSAGE['headers']->mdn_sent) 
     78  { 
     79    rcube_add_label('mdnrequest'); 
    7880    $OUTPUT->set_env('mdn_request', true); 
     81  } 
    7982 
    8083  $next = $prev = -1; 
  • trunk/roundcubemail/program/steps/settings/delete_identity.inc

    r543 r938  
    2222if (($ids = get_input_value('_iid', RCUBE_INPUT_GET)) && preg_match('/^[0-9]+(,[0-9]+)*$/', $ids)) 
    2323{ 
    24   $DB->query( 
    25     "UPDATE ".get_table_name('identities')." 
    26      SET    del=1 
    27      WHERE  user_id=? 
    28      AND    identity_id IN (".$ids.")", 
    29     $_SESSION['user_id']); 
    3024 
    31   $count = $DB->affected_rows(); 
    32   if ($count) 
     25  if ($USER->delete_identity($ids)) 
    3326    $OUTPUT->show_message('deletedsuccessfully', 'confirmation'); 
    3427 
  • trunk/roundcubemail/program/steps/settings/edit_identity.inc

    r543 r938  
    2222if (($_GET['_iid'] || $_POST['_iid']) && $_action=='edit-identity') 
    2323  { 
    24   $DB->query("SELECT * FROM ".get_table_name('identities')." 
    25               WHERE  identity_id=? 
    26               AND    user_id=? 
    27               AND    del<>1", 
    28               get_input_value('_iid', RCUBE_INPUT_GPC), 
    29               $_SESSION['user_id']); 
    30    
    31   $IDENTITY_RECORD = $DB->fetch_assoc(); 
     24  $IDENTITY_RECORD = $USER->get_identity(get_input_value('_iid', RCUBE_INPUT_GPC)); 
    3225   
    3326  if (is_array($IDENTITY_RECORD)) 
  • trunk/roundcubemail/program/steps/settings/func.inc

    r922 r938  
    2121 
    2222 
    23 // get user record 
    24 $sql_result = $DB->query("SELECT username, mail_host FROM ".get_table_name('users')." 
    25                           WHERE  user_id=?", 
    26                           $_SESSION['user_id']); 
    27                                   
    28 if ($USER_DATA = $DB->fetch_assoc($sql_result)) 
    29 { 
    30   $OUTPUT->set_pagetitle(rcube_label('settingsfor') . " ". $USER_DATA['username'] . (!strpos($USER_DATA['username'], '@') ? '@'.$USER_DATA['mail_host'] : '')); 
    31 } 
     23if ($USER->ID) 
     24  $OUTPUT->set_pagetitle(rcube_label('settingsfor') . " ". $USER->get_username()); 
    3225 
    3326 
     
    205198function rcmail_identities_list($attrib) 
    206199  { 
    207   global $DB, $CONFIG, $OUTPUT; 
    208  
    209  
    210   // get contacts from DB 
    211   $sql_result = $DB->query("SELECT * FROM ".get_table_name('identities')." 
    212                             WHERE  del<>1 
    213                             AND    user_id=? 
    214                             ORDER BY standard DESC, name ASC", 
    215                             $_SESSION['user_id']); 
    216  
     200  global $OUTPUT, $USER; 
    217201 
    218202  // add id to message list table if not specified 
     
    224208 
    225209  // create XHTML table   
    226   $out = rcube_table_output($attrib, $sql_result, $a_show_cols, 'identity_id'); 
     210  $out = rcube_table_output($attrib, $USER->list_identities(), $a_show_cols, 'identity_id'); 
    227211   
    228212  // set client env 
  • trunk/roundcubemail/program/steps/settings/save_identity.inc

    r543 r938  
    3434 
    3535 
     36$save_data = array(); 
     37foreach ($a_save_cols as $col) 
     38{ 
     39  $fname = '_'.$col; 
     40  if (isset($_POST[$fname])) 
     41    $save_data[$col] = get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)); 
     42} 
     43 
     44// set "off" values for checkboxes that were not checked, and therefore 
     45// not included in the POST body. 
     46foreach ($a_boolean_cols as $col) 
     47{ 
     48  $fname = '_' . $col; 
     49  if (!isset($_POST[$fname])) 
     50    $save_data[$col] = 0; 
     51} 
     52 
     53 
    3654// update an existing contact 
    3755if ($_POST['_iid']) 
     56{ 
     57  if ($updated = $USER->update_identity(get_input_value('_iid', RCUBE_INPUT_POST), $save_data)) 
    3858  { 
    39   $a_write_sql = array(); 
    40  
    41   foreach ($a_save_cols as $col) 
    42     { 
    43     $fname = '_'.$col; 
    44     if (isset($_POST[$fname])) 
    45       $a_write_sql[] = sprintf("%s=%s", 
    46         $DB->quoteIdentifier($col), 
    47         $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)))); 
    48     } 
    49  
    50   // set "off" values for checkboxes that were not checked, and therefore 
    51   // not included in the POST body. 
    52   foreach ($a_boolean_cols as $col) 
    53     { 
    54     $fname = '_' . $col; 
    55     if (!isset($_POST[$fname])) 
    56       $a_write_sql[] = sprintf("%s=0", $DB->quoteIdentifier($col)); 
    57     } 
    58  
    59   if (sizeof($a_write_sql)) 
    60     { 
    61     $DB->query( 
    62       "UPDATE ".get_table_name('identities')." 
    63        SET ".join(', ', $a_write_sql)." 
    64        WHERE  identity_id=? 
    65        AND    user_id=? 
    66        AND    del<>1", 
    67       get_input_value('_iid', RCUBE_INPUT_POST), 
    68       $_SESSION['user_id']); 
    69                         
    70     $updated = $DB->affected_rows(); 
    71     } 
    72         
    73   if ($updated) 
    74     { 
    7559    $OUTPUT->show_message('successfullysaved', 'confirmation'); 
    7660     
     
    7963     
    8064    if ($_POST['_framed']) 
    81       { 
     65    { 
    8266      // update the changed col in list 
    8367      // ...       
    84       } 
    8568    } 
     69  } 
    8670  else if ($DB->is_error()) 
    87     { 
     71  { 
    8872    // show error message 
    8973    $OUTPUT->show_message('errorsaving', 'error'); 
    9074    rcmail_overwrite_action('edit-identitiy'); 
    9175    return; 
    92     } 
    9376  } 
     77} 
    9478 
    9579// insert a new contact 
    9680else 
     81{ 
     82  if ($insert_id = $USER->insert_identity($save_data)) 
    9783  { 
    98   $a_insert_cols = $a_insert_values = array(); 
    99  
    100   foreach ($a_save_cols as $col) 
    101     { 
    102     $fname = '_'.$col; 
    103     if (!isset($_POST[$fname])) 
    104       continue; 
    105      
    106     $a_insert_cols[] = $DB->quoteIdentifier($col); 
    107     $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols))); 
    108     } 
    109      
    110   if (sizeof($a_insert_cols)) 
    111     { 
    112     $DB->query("INSERT INTO ".get_table_name('identities')." 
    113                 (user_id, ".join(', ', $a_insert_cols).") 
    114                 VALUES (?, ".join(', ', $a_insert_values).")", 
    115                 $_SESSION['user_id']); 
    116  
    117     $insert_id = $DB->insert_id(get_sequence_name('identities')); 
    118     } 
    119      
    120   if ($insert_id) 
    121     { 
    12284    $_GET['_iid'] = $insert_id; 
    12385 
     
    12688 
    12789    if ($_POST['_framed']) 
    128       { 
     90    { 
    12991      // add contact row or jump to the page where it should appear 
    13092      // .... 
    131       } 
    13293    } 
     94  } 
    13395  else 
    134     { 
     96  { 
    13597    // show error message 
    13698    $OUTPUT->show_message('errorsaving', 'error'); 
    13799    rcmail_overwrite_action('edit-identity'); 
    138100    return; 
    139     } 
    140101  } 
     102} 
    141103 
    142104 
    143105// mark all other identities as 'not-default' 
    144106if ($default_id) 
    145   $DB->query( 
    146     "UPDATE ".get_table_name('identities')." 
    147      SET ".$DB->quoteIdentifier('standard')."='0' 
    148      WHERE  user_id=? 
    149      AND    identity_id<>? 
    150      AND    del<>1", 
    151     $_SESSION['user_id'], 
    152     $default_id); 
     107  $USER->set_default($default_id); 
    153108 
    154109// go to next step 
  • trunk/roundcubemail/program/steps/settings/save_prefs.inc

    r768 r938  
    4545// force min size 
    4646if ($a_user_prefs['pagesize'] < 1) 
    47   { 
    4847  $a_user_prefs['pagesize'] = 10; 
    49   } 
     48 
    5049if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['pagesize'] > $CONFIG['max_pagesize'])) 
    51   { 
    5250  $a_user_prefs['pagesize'] = (int) $CONFIG['max_pagesize']; 
    53   } 
    5451 
    55 if (rcmail_save_user_prefs($a_user_prefs)) 
     52if ($USER->save_prefs($a_user_prefs)) 
    5653  $OUTPUT->show_message('successfullysaved', 'confirmation'); 
    5754 
  • trunk/roundcubemail/skins/default/mail.css

    r846 r938  
    633633  position:relative; 
    634634  min-height: 300px; 
    635   padding-top: 10px; 
    636635  padding-bottom: 10px; 
    637636  background-color: #FFFFFF; 
     
    640639div.message-part 
    641640{ 
    642   padding: 8px; 
    643   padding-top: 10px; 
    644   overflow: hidden; 
     641  padding: 10px 8px; 
     642  border-top: 1px solid #ccc; 
     643/*  overflow: hidden; */ 
     644} 
     645 
     646#messagebody div:first-child 
     647{ 
     648  border-top: 0; 
    645649} 
    646650 
Note: See TracChangeset for help on using the changeset viewer.