+ $_SESSION['compose']['forward_attachments'] = true;
+
+ return $cid_map;
+}
+
+
+function rcmail_write_inline_attachments(&$message)
+{
+ global $RCMAIL;
+
+ $cid_map = array();
+ foreach ((array)$message->mime_parts as $pid => $part) {
+ if (($part->content_id || $part->content_location) && $part->filename) {
+ if ($attachment = rcmail_save_attachment($message, $pid)) {
+ $_SESSION['compose']['attachments'][$attachment['id']] = $attachment;
+ $url = $RCMAIL->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'];
+ if ($part->content_id)
+ $cid_map['cid:'.$part->content_id] = $url;
+ else
+ $cid_map[$part->content_location] = $url;
+ }
+ }
+ }
+
+ return $cid_map;
+}
+
+function rcmail_save_attachment(&$message, $pid)
+{
+ $part = $message->mime_parts[$pid];
+ $mem_limit = parse_bytes(ini_get('memory_limit'));
+ $curr_mem = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB
+ $data = $path = null;
+
+ // don't load too big attachments into memory
+ if ($mem_limit > 0 && $part->size > $mem_limit - $curr_mem) {
+ $rcmail = rcmail::get_instance();
+ $temp_dir = unslashify($rcmail->config->get('temp_dir'));
+ $path = tempnam($temp_dir, 'rcmAttmnt');
+ if ($fp = fopen($path, 'w')) {
+ $message->get_part_content($pid, $fp);
+ fclose($fp);
+ } else
+ return false;
+ } else {
+ $data = $message->get_part_content($pid);
+ }
+
+ $attachment = array(
+ 'name' => $part->filename ? $part->filename : 'Part_'.$pid.'.'.$part->ctype_secondary,
+ 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
+ 'content_id' => $part->content_id,
+ 'data' => $data,
+ 'path' => $path,
+ 'size' => $path ? filesize($path) : strlen($data),
+ );
+
+ $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
+
+ if ($attachment['status']) {
+ unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']);
+ return $attachment;
+ } else if ($path) {
+ @unlink($path);
+ }
+
+ return false;
+}
+
+function rcmail_save_image($path, $mimetype='')
+{
+ // handle attachments in memory
+ $data = file_get_contents($path);
+
+ $attachment = array(
+ 'name' => rcmail_basename($path),
+ 'mimetype' => $mimetype ? $mimetype : rc_mime_content_type($path, $name),
+ 'data' => $data,
+ 'size' => strlen($data),
+ );
+
+ $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
+
+ if ($attachment['status']) {
+ unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']);
+ return $attachment;
+ }
+
+ return false;
+}
+
+function rcmail_basename($filename)
+{
+ // basename() is not unicode safe and locale dependent
+ if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware')) {
+ return preg_replace('/^.*[\\\\\\/]/', '', $filename);
+ } else {
+ return preg_replace('/^.*[\/]/', '', $filename);
+ }
+}