Changeset 4315b00 in github


Ignore:
Timestamp:
Dec 10, 2007 11:20:01 PM (5 years ago)
Author:
svncommit <devs@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
338551d
Parents:
deb3026
Message:

added ability to insert attached images in HTML editor

Files:
1 added
8 edited
1 moved

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    rdeb3026 r4315b00  
    55---------- 
    66- Upgrade to TinyMCE 2.1.3 
     7- Allow inserting image attachments into HTML messages while composing  
    78 
    892007/12/10 (thomasb) 
  • index.php

    rfba1f5a r4315b00  
    284284    include('program/steps/mail/upload.inc'); 
    285285 
    286   if ($_action=='compose' || $_action=='remove-attachment') 
     286  if ($_action=='compose' || $_action=='remove-attachment' || $_action=='display-attachment') 
    287287    include('program/steps/mail/compose.inc'); 
    288288 
  • program/js/app.js

    rfba1f5a r4315b00  
    831831        if (!this.check_compose_input()) 
    832832          break; 
    833            
     833 
    834834        // Reset the auto-save timer 
    835835        self.clearTimeout(this.save_timer); 
     
    18851885  this.upload_file = function(form) 
    18861886    { 
    1887      
    18881887    if (!form) 
    18891888      return false; 
  • program/js/editor.js

    r8094288 r4315b00  
    3030                 extended_valid_elements : 'font[face|size|color|style],span[id|class|align|style]', 
    3131                 content_css : skin_path + '/editor_content.css', 
    32                  popups_css : skin_path + '/editor_popup.css', 
    33                  editor_css : skin_path + '/editor_ui.css' 
     32                 editor_css : skin_path + '/editor_ui.css', 
     33                 external_image_list_url : 'program/js/editor_images.js' 
    3434               }); 
    3535  } 
  • program/js/tiny_mce/themes/advanced/editor_template_src.js

    rdeb3026 r4315b00  
    14211421        _insertImage : function(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout) { 
    14221422                tinyMCE.execCommand("mceInsertContent", false, tinyMCE.createTagHTML('img', { 
    1423                         src : tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src), // Force absolute 
     1423                        src : tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, src), // Force absolute 
    14241424                        mce_src : src, 
    14251425                        alt : alt, 
  • program/steps/mail/compose.inc

    rfba1f5a r4315b00  
    3131// remove an attachment 
    3232if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs)) 
    33   { 
     33{ 
    3434  $id = $regs[1]; 
    3535  if (is_array($_SESSION['compose']['attachments'][$id])) 
    36     { 
     36  { 
    3737    @unlink($_SESSION['compose']['attachments'][$id]['path']); 
    3838    $_SESSION['compose']['attachments'][$id] = NULL; 
     
    4040    $OUTPUT->send(); 
    4141    exit; 
    42     } 
    43   } 
    44  
     42  } 
     43} 
     44 
     45if ($_action=='display-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs)) 
     46{ 
     47  $id = $regs[1]; 
     48  if (is_array($_SESSION['compose']['attachments'][$id])) 
     49  { 
     50    $apath = $_SESSION['compose']['attachments'][$id]['path']; 
     51    header('Content-Type: ' . $_SESSION['compose']['attachments'][$id]['mimetype']); 
     52    header('Content-Length: ' . filesize($apath)); 
     53    readfile($apath); 
     54  } 
     55  exit; 
     56} 
    4557 
    4658$MESSAGE_FORM = NULL; 
     
    5365 
    5466if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET)) 
    55   { 
     67{ 
    5668  rcmail_compose_cleanup(); 
    5769  $_SESSION['compose'] = array('id' => uniqid(rand())); 
    58   } 
     70} 
    5971 
    6072// add some labels to client 
     
    7587 
    7688if (!empty($msg_uid)) 
    77   { 
     89{ 
    7890  // similar as in program/steps/mail/show.inc 
    7991  $MESSAGE = array('UID' => $msg_uid); 
     
    8496   
    8597  if ($compose_mode == RCUBE_COMPOSE_REPLY) 
    86     { 
     98  { 
    8799    $_SESSION['compose']['reply_uid'] = $msg_uid; 
    88100    $_SESSION['compose']['reply_msgid'] = $MESSAGE['headers']->messageID; 
     
    91103    if (!empty($_GET['_all'])) 
    92104      $MESSAGE['reply_all'] = 1; 
    93     } 
     105  } 
    94106  else if ($compose_mode == RCUBE_COMPOSE_FORWARD) 
    95     { 
     107  { 
    96108    $_SESSION['compose']['forward_uid'] = $msg_uid; 
    97     } 
     109  } 
    98110  else if ($compose_mode == RCUBE_COMPOSE_DRAFT) 
    99     { 
     111  { 
    100112    $_SESSION['compose']['draft_uid'] = $msg_uid; 
    101     } 
    102  
    103   } 
     113  } 
     114} 
    104115 
    105116/****** compose mode functions ********/ 
     
    107118 
    108119function rcmail_compose_headers($attrib) 
    109   { 
     120{ 
    110121  global $IMAP, $MESSAGE, $DB, $compose_mode; 
    111122  static $sa_recipients = array(); 
     
    117128   
    118129  switch ($part) 
    119     { 
     130  { 
    120131    case 'from': 
    121132      return rcmail_compose_header_from($attrib); 
     
    133144    case 'cc': 
    134145      if (!$fname) 
    135         { 
     146      { 
    136147        $fname = '_cc'; 
    137148        $header = 'cc'; 
    138         } 
     149      } 
    139150    case 'bcc': 
    140151      if (!$fname) 
    141         { 
     152      { 
    142153        $fname = '_bcc'; 
    143154        $header = 'bcc'; 
    144         } 
     155      } 
    145156         
    146157      $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'tabindex'); 
     
    153164      $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex'); 
    154165      $field_type = 'textfield'; 
    155       break; 
    156      
    157     } 
     166      break;     
     167  } 
    158168  
    159169  if ($fname && !empty($_POST[$fname])) 
     
    161171 
    162172  else if ($header && $compose_mode == RCUBE_COMPOSE_REPLY) 
    163     { 
     173  { 
    164174    // get recipent address(es) out of the message headers 
    165175    if ($header=='to' && !empty($MESSAGE['headers']->replyto)) 
     
    171181    // add recipent of original message if reply to all 
    172182    else if ($header=='cc' && !empty($MESSAGE['reply_all'])) 
    173       { 
     183    { 
    174184      if ($v = $MESSAGE['headers']->to) 
    175185        $fvalue .= $v; 
     
    177187      if ($v = $MESSAGE['headers']->cc) 
    178188        $fvalue .= (!empty($fvalue) ? ', ' : '') . $v; 
    179       } 
     189    } 
    180190 
    181191    // split recipients and put them back together in a unique way 
    182192    if (!empty($fvalue)) 
    183       { 
     193    { 
    184194      $to_addresses = $IMAP->decode_address_list($fvalue); 
    185195      $fvalue = ''; 
    186196      foreach ($to_addresses as $addr_part) 
     197      { 
     198        if (!empty($addr_part['mailto']) && !in_array($addr_part['mailto'], $sa_recipients) && (!$MESSAGE['FROM'] || !in_array($addr_part['mailto'], $MESSAGE['FROM']))) 
    187199        { 
    188         if (!empty($addr_part['mailto']) && !in_array($addr_part['mailto'], $sa_recipients) && (!$MESSAGE['FROM'] || !in_array($addr_part['mailto'], $MESSAGE['FROM']))) 
    189           { 
    190200          $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string']; 
    191201          $sa_recipients[] = $addr_part['mailto']; 
    192           } 
    193202        } 
    194203      } 
    195204    } 
     205  } 
    196206  else if ($header && $compose_mode == RCUBE_COMPOSE_DRAFT) 
    197     { 
     207  { 
    198208    // get drafted headers 
    199209    if ($header=='to' && !empty($MESSAGE['headers']->to)) 
     
    205215    if ($header=='bcc' && !empty($MESSAGE['headers']->bcc)) 
    206216      $fvalue = $IMAP->decode_header($MESSAGE['headers']->bcc); 
    207     } 
     217  } 
    208218 
    209219         
    210220  if ($fname && $field_type) 
    211     { 
     221  { 
    212222    // pass the following attributes to the form class 
    213223    $field_attrib = array('name' => $fname); 
     
    219229    $input = new $field_type($field_attrib); 
    220230    $out = $input->show($fvalue);     
    221     } 
     231  } 
    222232   
    223233  if ($form_start) 
     
    225235 
    226236  return $out;   
    227   } 
     237} 
    228238 
    229239 
    230240 
    231241function rcmail_compose_header_from($attrib) 
    232   { 
     242{ 
    233243  global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $compose_mode; 
    234244     
     
    242252  $a_recipients = array(); 
    243253  if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE['headers'])) 
    244     { 
     254  { 
    245255    $MESSAGE['FROM'] = array(); 
    246256 
    247257    $a_to = $IMAP->decode_address_list($MESSAGE['headers']->to); 
    248258    foreach ($a_to as $addr) 
    249       { 
     259    { 
    250260      if (!empty($addr['mailto'])) 
    251261        $a_recipients[] = $addr['mailto']; 
    252       } 
     262    } 
    253263 
    254264    if (!empty($MESSAGE['headers']->cc)) 
    255       { 
     265    { 
    256266      $a_cc = $IMAP->decode_address_list($MESSAGE['headers']->cc); 
    257267      foreach ($a_cc as $addr) 
    258         { 
     268      { 
    259269        if (!empty($addr['mailto'])) 
    260270          $a_recipients[] = $addr['mailto']; 
    261         } 
    262       } 
    263     } 
     271      } 
     272    } 
     273  } 
    264274 
    265275  // get this user's identities 
     
    267277 
    268278  if ($DB->num_rows($sql_result)) 
    269     { 
     279  { 
    270280    $from_id = 0; 
    271281    $a_signatures = array(); 
     
    275285 
    276286    while ($sql_arr = $DB->fetch_assoc($sql_result)) 
    277       { 
     287    { 
    278288      $identity_id = $sql_arr['identity_id']; 
    279289      $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id); 
     
    281291      // add signature to array 
    282292      if (!empty($sql_arr['signature'])) 
    283         { 
     293      { 
    284294        $a_signatures[$identity_id]['text'] = $sql_arr['signature']; 
    285295        $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false; 
    286296        if ($a_signatures[$identity_id]['is_html']) 
    287           { 
     297        { 
    288298            $h2t = new html2text($a_signatures[$identity_id]['text'], false, false); 
    289299            $plainTextPart = $h2t->get_text(); 
    290300            $a_signatures[$identity_id]['plain_text'] = trim($plainTextPart); 
    291           } 
    292301        } 
     302      } 
    293303 
    294304      // set identity if it's one of the reply-message recipients 
     
    301311      if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE['headers']->from, $sql_arr['email'])) 
    302312        $from_id = $sql_arr['identity_id']; 
    303       } 
     313    } 
    304314 
    305315    // overwrite identity selection with post parameter 
     
    311321    // add signatures to client 
    312322    $OUTPUT->set_env('signatures', $a_signatures); 
    313     } 
     323  } 
    314324  else 
    315     { 
     325  { 
    316326    $input_from = new textfield($field_attrib); 
    317327    $out = $input_from->show($_POST['_from']); 
    318     } 
     328  } 
    319329   
    320330  if ($form_start) 
     
    322332 
    323333  return $out; 
    324   } 
    325  
    326    
     334} 
     335 
    327336 
    328337function rcmail_compose_body($attrib) 
    329   { 
     338{ 
    330339  global $CONFIG, $OUTPUT, $MESSAGE, $compose_mode; 
    331340   
     
    458467 
    459468  return $out; 
    460   } 
     469} 
    461470 
    462471 
    463472function rcmail_create_reply_body($body, $bodyIsHtml) 
    464   { 
     473{ 
    465474  global $IMAP, $MESSAGE; 
    466475 
     
    475484    // add > to each line 
    476485    for($n=0; $n<sizeof($a_lines); $n++) 
    477       { 
     486    { 
    478487      if (strpos($a_lines[$n], '>')===0) 
    479488        $a_lines[$n] = '>'.$a_lines[$n]; 
    480489      else 
    481490        $a_lines[$n] = '> '.$a_lines[$n]; 
    482       } 
     491    } 
    483492  
    484493    $body = join("\n", $a_lines); 
     
    499508  else 
    500509  { 
    501      $prefix = sprintf("<br><br>On %s, %s wrote:<br><blockquote type=\"cite\" " . 
    502                        "style=\"padding-left: 5px; border-left: #1010ff 2px solid; " . 
    503                        "margin-left: 5px; width: 100%%\">", 
    504                        $MESSAGE['headers']->date, 
    505                        $IMAP->decode_header($MESSAGE['headers']->from)); 
    506  
    507      $suffix = "</blockquote>"; 
     510    $prefix = sprintf("<br><br>On %s, %s wrote:<br><blockquote type=\"cite\" " . 
     511                      "style=\"padding-left: 5px; border-left: #1010ff 2px solid; " . 
     512                      "margin-left: 5px; width: 100%%\">", 
     513                      $MESSAGE['headers']->date, 
     514                      $IMAP->decode_header($MESSAGE['headers']->from)); 
     515 
     516    $suffix = "</blockquote>"; 
    508517  } 
    509518 
    510519  return $prefix.$body.$suffix; 
    511   } 
     520} 
    512521 
    513522 
    514523function rcmail_create_forward_body($body, $bodyIsHtml) 
    515   { 
     524{ 
    516525  global $IMAP, $MESSAGE; 
    517526 
     
    529538  else 
    530539  { 
    531       $prefix = sprintf( 
     540    $prefix = sprintf( 
    532541        "<br><br>-------- Original Message --------" . 
    533542        "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" . 
     
    548557     
    549558  return $prefix.$body; 
    550   } 
     559} 
    551560 
    552561 
    553562function rcmail_create_draft_body($body, $bodyIsHtml) 
    554   { 
     563{ 
    555564  global $IMAP, $MESSAGE; 
    556565     
     
    561570 
    562571  return $body; 
    563   } 
     572} 
    564573   
    565574   
    566575function rcmail_write_compose_attachments(&$message) 
    567   { 
     576{ 
    568577  global $IMAP, $CONFIG; 
    569578 
     
    574583   
    575584  foreach ($message['parts'] as $pid => $part) 
    576     { 
     585  { 
    577586    if ($part->ctype_primary != 'message' && $part->ctype_primary != 'text' && 
    578587        ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] || 
    579588         (empty($part->disposition) && $part->filename))) 
    580       { 
     589    { 
    581590      $tmp_path = tempnam($temp_dir, 'rcmAttmnt'); 
    582591      if ($fp = fopen($tmp_path, 'w')) 
    583         { 
     592      { 
    584593        fwrite($fp, $IMAP->get_message_part($message['UID'], $pid, $part->encoding)); 
    585594        fclose($fp); 
     
    590599          'path' => $tmp_path 
    591600          ); 
    592         } 
    593       } 
    594     } 
     601      } 
     602    } 
     603  } 
    595604         
    596605  $_SESSION['compose']['forward_attachments'] = TRUE; 
    597   } 
     606} 
    598607 
    599608 
    600609function rcmail_compose_subject($attrib) 
    601   { 
     610{ 
    602611  global $CONFIG, $MESSAGE, $compose_mode; 
    603612   
     
    616625  // create a reply-subject 
    617626  else if ($compose_mode == RCUBE_COMPOSE_REPLY) 
    618     { 
     627  { 
    619628    if (eregi('^re:', $MESSAGE['subject'])) 
    620629      $subject = $MESSAGE['subject']; 
    621630    else 
    622631      $subject = 'Re: '.$MESSAGE['subject']; 
    623     } 
     632  } 
    624633 
    625634  // create a forward-subject 
    626635  else if ($compose_mode == RCUBE_COMPOSE_FORWARD) 
    627     { 
     636  { 
    628637    if (eregi('^fwd:', $MESSAGE['subject'])) 
    629638      $subject = $MESSAGE['subject']; 
    630639    else 
    631640      $subject = 'Fwd: '.$MESSAGE['subject']; 
    632     } 
     641  } 
    633642 
    634643  // creeate a draft-subject 
     
    641650          
    642651  return $out; 
    643   } 
     652} 
    644653 
    645654 
    646655function rcmail_compose_attachment_list($attrib) 
    647   { 
     656{ 
    648657  global $OUTPUT, $CONFIG; 
    649658   
     
    658667   
    659668  if (is_array($_SESSION['compose']['attachments'])) 
    660     { 
     669  { 
    661670    if ($attrib['deleteicon']) 
    662671      $button = sprintf('<img src="%s%s" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />', 
     
    675684                      $button, 
    676685                      Q($a_prop['name'])); 
    677     } 
     686  } 
    678687 
    679688  $OUTPUT->add_gui_object('attachmentlist', $attrib['id']); 
     
    681690  $out .= '</ul>'; 
    682691  return $out; 
    683   } 
    684  
     692} 
    685693 
    686694 
    687695function rcmail_compose_attachment_form($attrib) 
    688   { 
     696{ 
    689697  global $OUTPUT, $SESS_HIDDEN_FIELD; 
    690698 
     
    714722  $OUTPUT->add_gui_object('uploadbox', $attrib['id']); 
    715723  return $out; 
    716   } 
     724} 
    717725 
    718726 
    719727function rcmail_compose_attachment_field($attrib) 
    720   { 
     728{ 
    721729  // allow the following attributes to be added to the <input> tag 
    722730  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size')); 
     
    724732  $out = '<input type="file" name="_attachments[]"'. $attrib_str . " />"; 
    725733  return $out; 
    726   } 
     734} 
    727735 
    728736 
    729737function rcmail_priority_selector($attrib) 
    730   { 
     738{ 
    731739  list($form_start, $form_end) = get_form_tags($attrib); 
    732740  unset($attrib['form']); 
     
    749757          
    750758  return $out; 
    751   } 
     759} 
    752760 
    753761 
    754762function rcmail_receipt_checkbox($attrib) 
    755   { 
     763{ 
    756764  list($form_start, $form_end) = get_form_tags($attrib); 
    757765  unset($attrib['form']); 
     
    769777 
    770778  return $out; 
    771   } 
     779} 
    772780 
    773781 
     
    790798      $compose_mode == RCUBE_COMPOSE_FORWARD || 
    791799      $compose_mode == RCUBE_COMPOSE_DRAFT) 
    792     { 
     800  { 
    793801    $hasHtml = rcmail_has_html_part($MESSAGE['parts']); 
    794802    $useHtml = ($hasHtml && $CONFIG['htmleditor']); 
    795     } 
     803  } 
    796804 
    797805  $selector = ''; 
     
    800808  $attrib['onchange'] = 'return rcmail_toggle_editor(this)'; 
    801809  foreach ($choices as $value => $text) 
    802     { 
     810  { 
    803811    $checked = ''; 
    804812    if ((($value == 'html') && $useHtml) || 
     
    814822                         $attrib['id'], 
    815823                         rcube_label($text)); 
    816     } 
     824  } 
    817825 
    818826  return $selector; 
     
    821829 
    822830function get_form_tags($attrib) 
    823   { 
     831{ 
    824832  global $CONFIG, $OUTPUT, $MESSAGE_FORM, $SESS_HIDDEN_FIELD;   
    825833 
    826834  $form_start = ''; 
    827835  if (!strlen($MESSAGE_FORM)) 
    828     { 
     836  { 
    829837    $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task'])); 
    830838    $hiddenfields->add(array('name' => '_action', 'value' => 'send')); 
     
    833841    $form_start .= "\n$SESS_HIDDEN_FIELD\n"; 
    834842    $form_start .= $hiddenfields->show(); 
    835     } 
     843  } 
    836844     
    837845  $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : ''; 
     
    844852 
    845853  return array($form_start, $form_end);   
    846   } 
     854} 
    847855 
    848856 
     
    860868)); 
    861869 
    862  
    863870/****** get contacts for this user and add them to client scripts ********/ 
    864871 
     
    869876                                    
    870877if ($result = $CONTACTS->list_records()) 
    871   {         
     878{         
    872879  $a_contacts = array(); 
    873880  while ($sql_arr = $result->iterate()) 
     
    876883   
    877884  $OUTPUT->set_env('contacts', $a_contacts); 
    878   } 
    879  
     885} 
    880886 
    881887parse_template('compose'); 
  • program/steps/mail/sendmail.inc

    rfba1f5a r4315b00  
    249249// add stored attachments, if any 
    250250if (is_array($_SESSION['compose']['attachments'])) 
    251   foreach ($_SESSION['compose']['attachments'] as $attachment) 
    252     $MAIL_MIME->addAttachment($attachment['path'], $attachment['mimetype'], $attachment['name'], true, 'base64', 'attachment', $message_charset); 
     251  foreach ($_SESSION['compose']['attachments'] as $id => $attachment) 
     252  { 
     253    $dispurl = '/\ssrc\s*=\s*[\'"]?\S+display-attachment\S+file=rcmfile' . $id . '[\'"]?/'; 
     254    $match = preg_match($dispurl, $message_body); 
     255    if ($isHtml && ($match > 0)) 
     256    { 
     257      $message_body = preg_replace($dispurl, ' src="'.$attachment['name'].'"', $message_body); 
     258      $MAIL_MIME->setHTMLBody($message_body); 
     259      $MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name']); 
     260    } 
     261    else 
     262    { 
     263      $MAIL_MIME->addAttachment($attachment['path'], $attachment['mimetype'], $attachment['name'], true, 'base64', 'attachment', $message_charset); 
     264    } 
     265  } 
    253266 
    254267// add submitted attachments 
     
    383396  } 
    384397 
    385  
    386398?> 
  • program/steps/settings/edit_identity.inc

    rfba1f5a r4315b00  
    4444                                    "apply_source_formatting : true," . 
    4545                                    "content_css : '\$__skin_path' + '/editor_content.css'," . 
    46                                     "popups_css : '\$__skin_path' + '/editor_popups.css'," . 
    4746                                    "editor_css : '\$__skin_path' + '/editor_ui.css'," . 
    4847                                    "theme : 'advanced'," . 
Note: See TracChangeset for help on using the changeset viewer.