Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Fdl_Mail_Mime.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * redefine class to add explicit CID
8  * @deprecated use \Dcp\Mail\Message instead
9  */
10 class Fdl_Mail_mime extends Mail_mime
11 {
12  // USE TO ADD CID in attachment
13 
14  /**
15  * Adds a file to the list of attachments.
16  *
17  * @param string $file The file name of the file to attach
18  * OR the file data itself
19  * @param string $c_type The content type
20  * @param string $name The filename of the attachment
21  * Only use if $file is the file data
22  * @param bool $isFilename Whether $file is a filename or not
23  * Defaults to true
24  * @return mixed true on success or PEAR_Error object
25  * @access public
26  */
27  function addAttachment($file, $c_type = 'application/octet-stream', $name = '', $isfilename = true, $encoding = 'base64', $cid = '', $charset = "UTF-8", $language = '', $location = '', $n_encoding = null, $f_encoding = null, $description = '')
28  {
29  $filedata = ($isfilename === true) ? $this->_file2str($file) : $file;
30  if ($isfilename === true) {
31  // Force the name the user supplied, otherwise use $file
32  $filename = (!empty($name)) ? $name : basename($file);
33  } else {
34  $filename = $name;
35  }
36  if (empty($filename)) {
37  return PEAR::raiseError('The supplied filename for the attachment can\'t be empty');
38  }
39  if (PEAR::isError($filedata)) {
40  return $filedata;
41  }
42 
43  $this->_parts[] = array(
44  'body' => $filedata,
45  'name' => $filename,
46  'charset' => $charset,
47  'c_type' => $c_type,
48  'encoding' => $encoding
49  );
50  return true;
51  }
52 
53  function addAttachmentInline($file, $c_type = 'application/octet-stream', $name = '', $isfilename = true, $encoding = 'base64', $cid = '', $charset = "UTF-8")
54  {
55  $filedata = ($isfilename === true) ? $this->_file2str($file) : $file;
56  if ($isfilename === true) {
57  // Force the name the user supplied, otherwise use $file
58  $filename = (!empty($name)) ? $name : basename($file);
59  } else {
60  $filename = $name;
61  }
62  if (empty($filename)) {
63  return PEAR::raiseError('The supplied filename for the attachment can\'t be empty');
64  }
65  if (PEAR::isError($filedata)) {
66  return $filedata;
67  }
68 
69  $this->_parts[] = array(
70  'body' => $filedata,
71  'name' => $filename,
72  'charset' => $charset,
73  'c_type' => $c_type,
74  'encoding' => $encoding,
75  'disposition' => 'inline',
76  'cid' => $cid
77  );
78  return true;
79  }
80  /**
81  * Adds an attachment subpart to a mimePart object
82  * and returns it during the build process.
83  *
84  * @param Fdl_Mail_mimePart $obj The mimePart to add the image to
85  * @param array $value The attachment information
86  * @return Fdl_Mail_mimePart The image mimePart object
87  * @access private
88  */
89  function &_addAttachmentPart(&$obj, $value)
90  {
91  $params['content_type'] = $value['c_type'];
92  $params['encoding'] = $value['encoding'];
93  $params['dfilename'] = $value['name'];
94  $params['filename'] = $value['name'];
95  $params['charset'] = $value['charset'];
96 
97  if (isset($value['disposition'])) {
98  $params['disposition'] = $value['disposition'];
99  } else {
100  $params['disposition'] = 'attachment';
101  }
102 
103  if (isset($value['cid'])) {
104  $params['cid'] = $value['cid'];
105  }
106 
107  if (isset($value['name_encoding'])) {
108  $params['name_encoding'] = $value['name_encoding'];
109  } else {
110  $params['name_encoding'] = 'quoted-printable';
111  }
112 
113  if (isset($value['filename_encoding'])) {
114  $params['filename_encoding'] = $value['filename_encoding'];
115  } else {
116  $params['filename_encoding'] = 'quoted-printable';
117  }
118 
119  $obj->addSubpart($value['body'], $params);
120  }
121  function __construct($crlf = "\r\n")
122  {
123  parent::Mail_mime($crlf);
124  $this->_build_params['html_charset'] = 'UTF-8';
125  $this->_build_params['text_charset'] = 'UTF-8';
126  $this->_build_params['head_charset'] = 'UTF-8';
127  }
128 }
129 
130 class Fdl_Mail_mimePart extends Mail_mimePart
131 {
132  var $_filename = '';
133 
134  function Fdl_Mail_mimePart($body = '', $params = array())
135  {
136  // Keep track of the unaltered/unencoded filename for further use
137  if (isset($params['filename'])) {
138  $this->_filename = $params['filename'];
139  } elseif (isset($params['dfilename'])) {
140  $this->_filename = $params['dfilename'];
141  }
142 
143  parent::Mail_mimePart($body, $params);
144  }
145  /**
146  * @param string $body
147  * @param array $params
148  * @return Fdl_Mail_mimePart
149  */
150  function &addSubpart($body, $params)
151  {
152  if (!property_exists('Mail_mimePart', '_body_file') && isset($params['body_file'])) {
153  // Mail_mimePart < 1.6.0 has no support for passing a file with $param['body_file']
154  $body = file_get_contents($params['body_file']);
155  unset($params['body_file']);
156  }
157  $this->_subparts[] = new Fdl_Mail_mimePart($body, $params);
158  return $this->_subparts[count($this->_subparts) - 1];
159  }
160 
161  function setBodyFile($file)
162  {
163  if (!property_Exists('Mail_mimePart', '_body_file')) {
164  // Mail_mimePart < 1.6.0
165  $this->_body = file_get_contents($file);
166  } else {
167  $this->_body_file = $file;
168  }
169  return $this;
170  }
171 }
$filename
$file
& addSubpart($body, $params)
Fdl_Mail_mimePart($body= '', $params=array())
if(!$img) $location
Definition: resizeimg.php:143
addAttachmentInline($file, $c_type= 'application/octet-stream', $name= '', $isfilename=true, $encoding= 'base64', $cid= '', $charset="UTF-8")
addAttachment($file, $c_type= 'application/octet-stream', $name= '', $isfilename=true, $encoding= 'base64', $cid= '', $charset="UTF-8", $language= '', $location= '', $n_encoding=null, $f_encoding=null, $description= '')
& _addAttachmentPart(&$obj, $value)
__construct($crlf="\r\n")
$value
← centre documentaire © anakeen