Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmailfunctions.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezmailfunctions.php 6394 2001-08-08 12:34:57Z jhe $
5 //
6 // Created on: <23-Oct-2000 17:53:46 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "ezmail/classes/ezmail.php" );
28 // include_once( "classes/ezfile.php" );
29 // include_once( "ezfilemanager/classes/ezvirtualfile.php" );
30
31 /* This file contains a list of functions that are used by the various classes.
32 They are put here because they are generall and to keep the classes from beeing
33 crouded.*/
34
35
36
40 function getHeaders( &$mail, $imap_stream, $msgno )
41 {
42 $headers = imap_headerinfo( $imap_stream, $msgno );
43 // print( "To: " . getDecodedHeader( $headers->toaddress ). "<br>" );
44 // print( "From: " . getDecodedHeader( $headers->fromaddress ). "<br>"); // from NAME
45 // print( "Reply: " . getDecodedHeader( $headers->reply_toaddress ) ."<br>");
46 // print( "Subject: " . getDecodedHeader( $headers->subject )."<br>");
47 // print( "MessageID: " . getDecodedHeader( $headers->message_id ). "<br>" );
48 // print( "Date: " . getDecodedHeader( $headers->date ) . "<br>" );
49 // print( "ReplyID: " . getDecodedHeader( $headers->in_reply_to ). "<br>" );
50
51 $mail->setTo( getDecodedHeader( $headers->toaddress ) );
52 $mail->setFrom( getDecodedHeader( $headers->fromaddress ) ); // from NAME
53 $mail->setReplyTo( getDecodedHeader( $headers->reply_toaddress ) );
54 $mail->setSubject( getDecodedHeader( $headers->subject ) );
55 $mail->setMessageID( getDecodedHeader( $headers->message_id ) );
56 // print( "Date: " . getDecodedHeader( $headers->date ) . "<br>" );
57 $mail->setReferences( getDecodedHeader( $headers->in_reply_to ) );
58 }
59
60 /*
61 Decodes a header and returns it. (Support for non ASCII characters in mail header)
62 */
63 function getDecodedHeader( $headervalue )
64 {
65 $decode = imap_mime_header_decode( $headervalue );
66 $ret = "";
67 for( $i = 0; $i < count( $decode ); $i++ )
68 {
69 $ret = $i == 0 ? $decode[$i]->text : $ret . $decode[$i]->text;
70 }
71 return $ret;
72 }
73
74
75
76 //How to call this function:
77 //$msg_struct = imap_fetchstructure($mconn, $msg_no);
78 //
79 //disectThisPart($msg_struct, "");
80 //imap_fetchbody( $mbox, $msgnum, $partnum );
92 function disectThisPart( $this_part, $part_no, $mbox, $msgnum, &$mail, $level=0 )
93 {
95 if ( $this_part->ifdisposition )
96 {
97 if ( $this_part->disposition == "ATTACHMENT" || $this_part->disposition == "INLINE" )
98 {
99 // First see if they sent a filename
100 $att_name = "unknown";
101 for ( $lcv = 0; $lcv < count( $this_part->parameters ); $lcv++ )
102 {
103 $param = $this_part->parameters[$lcv];
104
105 if ( $param->attribute == "NAME" )
106 {
107 $att_name = $param->value;
108 break;
109 }
110 }
111 addAttachment( $mail, decode( $this_part->encoding, imap_fetchbody( $mbox, $msgnum, $part_no ) ), $att_name );
112 }
113 else // INLINE should be here! For now just handle it as an attachment.
114 {
115 // disposition can also be used for images in HTML (Inline)
116 }
117 }
118 else
119 {
121 switch ( $this_part->type )
122 {
124 case TYPETEXT:
125 {
126 $mime_type = "text";
127 $value = decode( $this_part->encoding, imap_fetchbody( $mbox, $msgnum, $part_no ) );
128 $mail->setBodyText( $value );
129 }
130 break;
132 case TYPEMULTIPART:
133 {
134 $mime_type = "multipart";
135 for ( $i = 0; $i < count( $this_part->parts ); $i++ )
136 {
137 if ( $level != 0 )
138 $part_no = $part_no.".";
139 else
140 $part_no = "";
141
142 for ( $i = 0; $i < count( $this_part->parts ); $i++ )
143 {
144 disectThisPart( $this_part->parts[$i], $part_no.( $i + 1 ), $mbox, $msgnum, $mail, 1 );
145 }
146 }
147 }
148 break;
151 case TYPEMESSAGE:
152 // $mime_type = "message";
153 case TYPEAPPLICATION:
154 // $mime_type = "application";
155 case TYPEAUDIO:
156 // $mime_type = "audio";
157 case TYPEIMAGE:
158 // $mime_type = "image";
159
160 case TYPEVIDEO:
161 // $mime_type = "video";
162 case TYPEMODEL:
163 $mime_type = "model";
164 $att_name = "unknown";
165 for ( $lcv = 0; $lcv < count( $this_part->parameters ); $lcv++ )
166 {
167 $param = $this_part->parameters[$lcv];
168
169 if ( $param->attribute == "NAME" )
170 {
171 $att_name = $param->value;
172 break;
173 }
174 }
175 addAttachment( $mail, decode( $this_part->encoding, imap_fetchbody( $mbox, $msgnum, $part_no ) ), $att_name );
176
178 default:
179 $mime_type = "unknown";
180 break;
181 }
182 $full_mime_type = $mime_type."/".$this_part->subtype;
183 }
184 }
185
190 function addAttachment( &$mail, &$data , $fileName )
191 {
192 $file = new eZFile();
193 $file->dumpDataToFile( $data, $fileName );
194
195 $uploadedFile = new eZVirtualFile();
196 $uploadedFile->setName( $fileName );
197 $uploadedFile->setDescription( "" );
198
199 $uploadedFile->setFile( $file );
200
201 $uploadedFile->store();
202
203 $mail->addFile( $uploadedFile );
204 }
205
209 function &decode( $enctype, &$value )
210 {
211 $ret = "";
212 switch ($enctype)
213 {
214 case ENC7BIT:
215 $ret = $value;
216 break;
217 case ENC8BIT:
218 $ret = $value;
219 break;
220 case ENCBINARY:
221 $ret = $value;
222 break;
223 case ENCBASE64:
224 $ret = imap_base64( $value );
225 break;
226 case ENCQUOTEDPRINTABLE:
227 $ret = imap_qprint( $value );
228 break;
229 case ENCOTHER:
230 $ret = $value;
231 // not sure if this needs decoding at all
232 break;
233 default: // what is this???
234 $ret = $value;
235 }
236 return $ret;
237 }
238
239
240 /******* FUNCTIONS BELOW THIS POINT ARE NOT USED AT THE MOMENT ******************/
241
242 function get_mime_type(&$structure)
243 {
244 $primary_mime_type = array("TEXT", "MULTIPART", "MESSAGE", "APPLICATION", "AUDIO", "IMAGE", "VIDEO", "OTHER");
245 if($structure->subtype)
246 {
247 return $primary_mime_type[(int) $structure->type] . '/' . $structure->subtype;
248 }
249 return "TEXT/PLAIN";
250 }
251
252
253 function getPart($stream, $msg_number, $mime_type, $structure = false, $part_number = false)
254 {
255 if(!$structure)
256 {
257 $structure = imap_fetchstructure($stream, $msg_number);
258 }
259 if($structure)
260 {
261 if($mime_type == get_mime_type($structure))
262 {
263 if(!$part_number)
264 {
265 $part_number = "1";
266 }
267 $text = imap_fetchbody($stream, $msg_number, $part_number);
268 if($structure->encoding == 3)
269 {
270 return imap_base64($text);
271 }
272 else if($structure->encoding == 4)
273 {
274 return imap_qprint($text);
275 }
276 else
277 {
278 return $text;
279 }
280 }
281 if($structure->type == 1) /* multipart */
282 {
283 while(list($index, $sub_structure) = each($structure->parts))
284 {
285 if($part_number)
286 {
287 $prefix = $part_number . '.';
288 }
289 $data = get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1));
290 if($data)
291 {
292 return $data;
293 }
294 }
295 }
296 }
297 return false;
298 }
299
300 ?>
$i
$i
Definition: admin/adlist.php:91
$level
$level
Definition: admin/message.php:106
eZFile
Tool class which has convencience functions for files and directories.
Definition: ezfile.php:19
eZVirtualFile
Definition: ezvirtualfile.php:42
$mail
$mail
Definition: ezbulkmail/admin/maillist.php:61
$fileName
if(eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user)==false) $fileName
Definition: ezfilemanager/user/filedownload.php:43
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$index
$index
Definition: ezforum/user/messageedit.php:36
disectThisPart
disectThisPart( $this_part, $part_no, $mbox, $msgnum, &$mail, $level=0)
Definition: ezmailfunctions.php:92
getDecodedHeader
getDecodedHeader( $headervalue)
Definition: ezmailfunctions.php:63
get_mime_type
get_mime_type(&$structure)
Definition: ezmailfunctions.php:242
addAttachment
addAttachment(&$mail, &$data, $fileName)
Definition: ezmailfunctions.php:190
getPart
getPart($stream, $msg_number, $mime_type, $structure=false, $part_number=false)
Definition: ezmailfunctions.php:253
getHeaders
getHeaders(&$mail, $imap_stream, $msgno)
Definition: ezmailfunctions.php:40
decode
& decode( $enctype, &$value)
Definition: ezmailfunctions.php:209
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$headers
$headers
Definition: requestpagelist.php:61
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.