@ -335,10 +335,8 @@ function rcmail_process_compose_params(&$COMPOSE)
/ / clean HTML message body which can be submitted by URL
/ / clean HTML message body which can be submitted by URL
if ( ! empty ( $ COMPOSE [ ' param ' ] [ ' body ' ] ) ) {
if ( ! empty ( $ COMPOSE [ ' param ' ] [ ' body ' ] ) ) {
if ( $ COMPOSE [ ' param ' ] [ ' html ' ] = strpos ( $ COMPOSE [ ' param ' ] [ ' body ' ] , ' < ' ) ! = = false ) {
if ( $ COMPOSE [ ' param ' ] [ ' html ' ] = strpos ( $ COMPOSE [ ' param ' ] [ ' body ' ] , ' < ' ) ! = = false ) {
$ wash_params = array ( ' safe ' = > false , ' inline_html ' = > true ) ;
$ COMPOSE [ ' param ' ] [ ' body ' ] = rcmail_wash_html ( $ COMPOSE [ ' param ' ] [ ' body ' ] , $ wash_params , array ( ) ) ;
$ COMPOSE [ ' param ' ] [ ' body ' ] = preg_replace ( ' / < ! - - [ ^ > \ n ] + > / ' , ' ' , $ COMPOSE [ ' param ' ] [ ' body ' ] ) ;
$ COMPOSE [ ' param ' ] [ ' body ' ] = preg_replace ( ' / < \ / ? body > / ' , ' ' , $ COMPOSE [ ' param ' ] [ ' body ' ] ) ;
$ wash_params = array ( ' safe ' = > false , ' inline_html ' = > true ) ;
$ COMPOSE [ ' param ' ] [ ' body ' ] = rcmail_prepare_html_body ( $ COMPOSE [ ' param ' ] [ ' body ' ] , $ wash_params ) ;
}
}
}
}
@ -497,7 +495,9 @@ function rcmail_spellchecker_init()
function rcmail_prepare_message_body ( )
function rcmail_prepare_message_body ( )
{
{
global $ RCMAIL , $ MESSAGE , $ COMPOSE , $ HTML_MODE ;
global $ RCMAIL , $ MESSAGE , $ COMPOSE , $ HTML_MODE , $ CID_MAP ;
$ CID_MAP = array ( ) ;
/ / use posted message body
/ / use posted message body
if ( ! empty ( $ _POST [ ' _message ' ] ) ) {
if ( ! empty ( $ _POST [ ' _message ' ] ) ) {
@ -520,6 +520,23 @@ function rcmail_prepare_message_body()
$ isHtml = rcmail_compose_editor_mode ( ) ;
$ isHtml = rcmail_compose_editor_mode ( ) ;
$ messages = array ( ) ;
$ messages = array ( ) ;
/ / save inline images to files ( before HTML body washing )
if ( $ COMPOSE [ ' mode ' ] = = rcmail_sendmail : : MODE_REPLY ) {
rcmail_write_inline_attachments ( $ MESSAGE ) ;
}
/ / save attachments to files ( before HTML body washing )
else {
rcmail_write_compose_attachments ( $ MESSAGE , $ isHtml ) ;
}
/ / set is_safe flag ( before HTML body washing )
if ( $ COMPOSE [ ' mode ' ] = = rcmail_sendmail : : MODE_DRAFT ) {
$ MESSAGE - > is_safe = true ;
}
else {
rcmail_check_safe ( $ MESSAGE ) ;
}
if ( ! empty ( $ MESSAGE - > parts ) ) {
if ( ! empty ( $ MESSAGE - > parts ) ) {
/ / collect IDs of message / rfc822 parts
/ / collect IDs of message / rfc822 parts
foreach ( $ MESSAGE - > mime_parts ( ) as $ part ) {
foreach ( $ MESSAGE - > mime_parts ( ) as $ part ) {
@ -579,7 +596,8 @@ function rcmail_prepare_message_body()
$ body = rcmail_create_draft_body ( $ body , $ isHtml ) ;
$ body = rcmail_create_draft_body ( $ body , $ isHtml ) ;
}
}
}
}
else { / / new message
/ / new message
else {
$ isHtml = rcmail_compose_editor_mode ( ) ;
$ isHtml = rcmail_compose_editor_mode ( ) ;
}
}
@ -635,6 +653,7 @@ function rcmail_compose_part_body($part, $isHtml = false)
if ( $ isHtml ) {
if ( $ isHtml ) {
if ( $ part - > ctype_secondary = = ' html ' ) {
if ( $ part - > ctype_secondary = = ' html ' ) {
$ body = rcmail_prepare_html_body ( $ body ) ;
}
}
else if ( $ part - > ctype_secondary = = ' enriched ' ) {
else if ( $ part - > ctype_secondary = = ' enriched ' ) {
$ body = rcube_enriched : : to_html ( $ body ) ;
$ body = rcube_enriched : : to_html ( $ body ) ;
@ -751,13 +770,6 @@ function rcmail_create_reply_body($body, $bodyIsHtml)
}
}
}
}
else {
else {
/ / save inline images to files
$ cid_map = rcmail_write_inline_attachments ( $ MESSAGE ) ;
/ / set is_safe flag ( we need this for html body washing )
rcmail_check_safe ( $ MESSAGE ) ;
/ / clean up html tags
$ body = rcmail_wash_html ( $ body , array ( ' safe ' = > $ MESSAGE - > is_safe ) , $ cid_map ) ;
$ suffix = ' ' ;
$ suffix = ' ' ;
if ( $ reply_indent ) {
if ( $ reply_indent ) {
@ -796,25 +808,9 @@ function rcmail_get_reply_header($message)
function rcmail_create_forward_body ( $ body , $ bodyIsHtml )
function rcmail_create_forward_body ( $ body , $ bodyIsHtml )
{
{
global $ RCMAIL , $ MESSAGE , $ COMPOS E ;
global $ MESSAGE ;
/ / add attachments
if ( ! isset ( $ COMPOSE [ ' forward_attachments ' ] ) & & is_array ( $ MESSAGE - > mime_parts ) ) {
$ cid_map = rcmail_write_compose_attachments ( $ MESSAGE , $ bodyIsHtml ) ;
}
if ( ! $ bodyIsHtml ) {
$ body = trim ( $ body , "\r\n" ) ;
}
else {
/ / set is_safe flag ( we need this for html body washing )
rcmail_check_safe ( $ MESSAGE ) ;
/ / clean up html tags
$ body = rcmail_wash_html ( $ body , array ( ' safe ' = > $ MESSAGE - > is_safe ) , $ cid_map ) ;
}
return rcmail_get_forward_header ( $ MESSAGE , $ bodyIsHtml ) . $ body ;
return rcmail_get_forward_header ( $ MESSAGE , $ bodyIsHtml ) . trim ( $ body , "\r\n" ) ;
}
}
function rcmail_get_forward_header ( $ message , $ bodyIsHtml = false , $ extended = true )
function rcmail_get_forward_header ( $ message , $ bodyIsHtml = false , $ extended = true )
@ -871,44 +867,48 @@ function rcmail_get_forward_header($message, $bodyIsHtml = false, $extended = tr
function rcmail_create_draft_body ( $ body , $ bodyIsHtml )
function rcmail_create_draft_body ( $ body , $ bodyIsHtml )
{
{
global $ MESSAGE , $ COMPOSE ;
/ / add attachments
/ / count ( $ MESSAGE - > mime_parts ) can be 1 - e . g . attachment , but no text !
if ( empty ( $ COMPOSE [ ' forward_attachments ' ] )
& & is_array ( $ MESSAGE - > mime_parts )
& & count ( $ MESSAGE - > mime_parts ) > 0
) {
$ cid_map = rcmail_write_compose_attachments ( $ MESSAGE , $ bodyIsHtml ) ;
}
/ / clean up HTML tags - XSS prevention ( # 1489251 )
if ( $ bodyIsHtml ) {
$ body = rcmail_wash_html ( $ body , array ( ' safe ' = > 1 ) , $ cid_map ) ;
/ / cleanup
$ body = preg_replace ( array (
/ / remove comments ( produced by washtml )
' / < ! - - [ ^ > ] + - - > / ' ,
/ / remove < body > tags
' / < body ( [ ^ > ] * ) > / i ' ,
' / < \ / body > / i ' ,
/ / convert TinyMCE ' s empty - line sequence ( # 1490463 )
' / < p > \ xC2 \ xA0 < \ / p > / ' ,
) ,
array (
' ' ,
' ' ,
' ' ,
' < p > < br / > < / p > ' ,
) ,
$ body
) ;
/ / replace cid with href in inline images links
if ( ! empty ( $ cid_map ) ) {
$ body = str_replace ( array_keys ( $ cid_map ) , array_values ( $ cid_map ) , $ body ) ;
}
/ / Return the draft body as - is
return $ body ;
}
/ / Clean up HTML content of Draft / Reply / Forward ( part of the message )
function rcmail_prepare_html_body ( $ body , $ wash_params = array ( ) )
{
global $ CID_MAP , $ MESSAGE , $ COMPOSE ;
static $ part_no ;
/ / Set attributes of the part container
$ container_id = $ COMPOSE [ ' mode ' ] . ' body ' . ( + + $ part_no ) ;
$ container_attrib = array ( ' id ' = > $ container_id ) ;
$ body_args = array (
' safe ' = > $ MESSAGE - > is_safe ,
' plain ' = > false ,
' css_prefix ' = > ' v ' . $ part_no ,
) ;
/ / remove comments ( produced by washtml )
$ replace = array ( ' / < ! - - [ ^ > ] + - - > / ' = > ' ' ) ;
if ( $ COMPOSE [ ' mode ' ] = = rcmail_sendmail : : MODE_DRAFT ) {
/ / convert TinyMCE ' s empty - line sequence ( # 1490463 )
$ replace [ ' / < p > \ xC2 \ xA0 < \ / p > / ' ] = ' < p > < br / > < / p > ' ;
/ / remove < body > tags
$ replace [ ' / < body ( [ ^ > ] * ) > / i ' ] = ' ' ;
$ replace [ ' / < \ / body > / i ' ] = ' ' ;
}
else {
$ body_args [ ' container_id ' ] = $ container_id ;
$ body_args [ ' container_attrib ' ] = $ container_attrib ;
}
/ / Make the HTML content safe and clean
$ body = rcmail_wash_html ( $ body , $ wash_params + $ body_args , $ CID_MAP ) ;
$ body = preg_replace ( array_keys ( $ replace ) , array_values ( $ replace ) , $ body ) ;
$ body = rcmail_html4inline ( $ body , $ body_args ) ;
if ( $ COMPOSE [ ' mode ' ] ! = rcmail_sendmail : : MODE_DRAFT ) {
$ body = html : : div ( $ container_attrib , $ body ) ;
}
}
return $ body ;
return $ body ;
@ -938,18 +938,17 @@ function rcmail_remove_signature($body)
function rcmail_write_compose_attachments ( & $ message , $ bodyIsHtml )
function rcmail_write_compose_attachments ( & $ message , $ bodyIsHtml )
{
{
global $ RCMAIL , $ COMPOSE ;
global $ RCMAIL , $ COMPOSE , $ CID_MAP ;
$ loaded_attachments = array ( ) ;
foreach ( ( array ) $ COMPOSE [ ' attachments ' ] as $ attachment ) {
$ loaded_attachments [ $ attachment [ ' name ' ] . $ attachment [ ' mimetype ' ] ] = $ attachment ;
if ( $ message - > pgp_mime | | ! empty ( $ COMPOSE [ ' forward_attachments ' ] ) ) {
return $ CID_MAP ;
}
}
$ cid_map = array ( ) ;
$ message s = array ( ) ;
$ messages = array ( ) ;
$ loaded_attachment s = array ( ) ;
if ( $ message - > pgp_mime ) {
return $ cid_ map ;
foreach ( ( array ) $ COMPOSE [ ' attachments ' ] as $ attachment ) {
$ loaded_attachments [ $ attachment [ ' name ' ] . $ atta chment [ ' m imetype ' ] ] = $ attachment ;
}
}
foreach ( ( array ) $ message - > mime_parts ( ) as $ pid = > $ part ) {
foreach ( ( array ) $ message - > mime_parts ( ) as $ pid = > $ part ) {
@ -993,9 +992,9 @@ function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
$ RCMAIL - > comm_path , $ COMPOSE [ ' id ' ] , $ attachment [ ' id ' ] ) ;
$ RCMAIL - > comm_path , $ COMPOSE [ ' id ' ] , $ attachment [ ' id ' ] ) ;
if ( $ part - > content_id )
if ( $ part - > content_id )
$ cid_map [ ' cid : ' . $ part - > content_id ] = $ url ;
$ CID_MAP [ ' cid : ' . $ part - > content_id ] = $ url ;
else
else
$ cid_map [ $ part - > content_location ] = $ url ;
$ CID_MAP [ $ part - > content_location ] = $ url ;
}
}
}
}
}
}
@ -1003,20 +1002,19 @@ function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
$ COMPOSE [ ' forward_attachments ' ] = true ;
$ COMPOSE [ ' forward_attachments ' ] = true ;
return $ cid_map ;
return $ CID_MAP ;
}
}
function rcmail_write_inline_attachments ( & $ message )
function rcmail_write_inline_attachments ( & $ message )
{
{
global $ RCMAIL , $ COMPOSE ;
$ cid_map = array ( ) ;
$ messages = array ( ) ;
global $ RCMAIL , $ COMPOSE , $ CID_MAP ;
if ( $ message - > pgp_mime ) {
if ( $ message - > pgp_mime ) {
return $ cid_map ;
return $ CID_MAP ;
}
}
$ messages = array ( ) ;
foreach ( ( array ) $ message - > mime_parts ( ) as $ pid = > $ part ) {
foreach ( ( array ) $ message - > mime_parts ( ) as $ pid = > $ part ) {
if ( $ part - > mimetype = = ' message / rfc822 ' ) {
if ( $ part - > mimetype = = ' message / rfc822 ' ) {
$ messages [ ] = $ part - > mime_id ;
$ messages [ ] = $ part - > mime_id ;
@ -1035,14 +1033,14 @@ function rcmail_write_inline_attachments(&$message)
$ RCMAIL - > comm_path , $ COMPOSE [ ' id ' ] , $ attachment [ ' id ' ] ) ;
$ RCMAIL - > comm_path , $ COMPOSE [ ' id ' ] , $ attachment [ ' id ' ] ) ;
if ( $ part - > content_id )
if ( $ part - > content_id )
$ cid_map [ ' cid : ' . $ part - > content_id ] = $ url ;
$ CID_MAP [ ' cid : ' . $ part - > content_id ] = $ url ;
else
else
$ cid_map [ $ part - > content_location ] = $ url ;
$ CID_MAP [ $ part - > content_location ] = $ url ;
}
}
}
}
}
}
return $ cid_map ;
return $ CID_MAP ;
}
}
/ / Creates attachment ( s ) from the forwarded message ( s )
/ / Creates attachment ( s ) from the forwarded message ( s )