commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / ezc / Mail / src / parts / fileparts / disk_file.php
1 <?php
2 /**
3 * File containing the ezcMailFile class
4 *
5 * @package Mail
6 * @version 1.7beta1
7 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
8 * @license http://ez.no/licenses/new_bsd New BSD License
9 */
10
11 /**
12 * Mail part for binary data from the file system.
13 *
14 * @package Mail
15 * @version 1.7beta1
16 */
17 class ezcMailFile extends ezcMailFilePart
18 {
19 /**
20 * Constructs a new attachment with $fileName.
21 *
22 * If the $mimeType and $contentType are not specified they are extracted
23 * with the fileinfo extension if it is available, otherwise they are set
24 * to application/octet-stream.
25 *
26 * @param string $fileName
27 * @param string $contentType
28 * @param string $mimeType
29 */
30 public function __construct( $fileName, $contentType = null, $mimeType = null )
31 {
32 parent::__construct( $fileName );
33
34 if ( $contentType != null && $mimeType != null )
35 {
36 $this->contentType = $contentType;
37 $this->mimeType = $mimeType;
38 }
39 elseif ( ezcBaseFeatures::hasExtensionSupport( 'fileinfo' ) )
40 {
41 // get mime and content type
42 $fileInfo = finfo_open( FILEINFO_MIME );
43 $mimeParts = finfo_file( $fileInfo, $fileName );
44 if ( $mimeParts !== false && strpos( $mimeParts, '/' ) !== false )
45 {
46 list( $this->contentType, $this->mimeType ) = explode( '/', $mimeParts );
47 }
48 else
49 {
50 // default to mimetype application/octet-stream
51 $this->contentType = self::CONTENT_TYPE_APPLICATION;
52 $this->mimeType = "octet-stream";
53 }
54 finfo_close( $fileInfo );
55 }
56 else
57 {
58 // default to mimetype application/octet-stream
59 $this->contentType = self::CONTENT_TYPE_APPLICATION;
60 $this->mimeType = "octet-stream";
61 }
62 }
63
64 /**
65 * Sets the property $name to $value.
66 *
67 * @throws ezcBasePropertyNotFoundException
68 * if the property does not exist.
69 * @throws ezcBaseFileNotFoundException
70 * when setting the property with an invalid filename.
71 * @param string $name
72 * @param mixed $value
73 * @ignore
74 */
75 public function __set( $name, $value )
76 {
77 switch ( $name )
78 {
79 case 'fileName':
80 if ( is_readable( $value ) )
81 {
82 parent::__set( $name, $value );
83 }
84 else
85 {
86 throw new ezcBaseFileNotFoundException( $value );
87 }
88 break;
89 default:
90 return parent::__set( $name, $value );
91 break;
92 }
93 }
94
95 /**
96 * Returns the value of property $value.
97 *
98 * @throws ezcBasePropertyNotFoundException
99 * if the property does not exist.
100 * @param string $name
101 * @return mixed
102 * @ignore
103 */
104 public function __get( $name )
105 {
106 switch ( $name )
107 {
108 default:
109 return parent::__get( $name );
110 break;
111 }
112 }
113
114 /**
115 * Returns true if the property $name is set, otherwise false.
116 *
117 * @param string $name
118 * @return bool
119 * @ignore
120 */
121 public function __isset( $name )
122 {
123 switch ( $name )
124 {
125 default:
126 return parent::__isset( $name );
127 }
128 }
129
130 /**
131 * Returns the contents of the file with the correct encoding.
132 *
133 * @return string
134 */
135 public function generateBody()
136 {
137 return chunk_split( base64_encode( file_get_contents( $this->fileName ) ), 76, ezcMailTools::lineBreak() );
138 }
139 }
140 ?>