Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmailaccount.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezmailaccount.php 6657 2001-08-27 10:54:12Z jhe $
5 //
6 // eZMailAccount class
7 //
8 // Created on: <19-Mar-2001 17:58:38 fh>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
29
32
40 /* ATTENTION:
41 Lots of this code is build upon imap specific features. If you want to understand how this stuff works
42 you can find info here www.faqs.org about the protocols:
43 RFC821: Simple Mail Transfer Protocol (SMTP).
44 RFC822: Standard for ARPA internet text messages.
45 RFC2060: Internet Message Access Protocol (IMAP) Version 4rev1.
46 RFC1939: Post Office Protocol Version 3 (POP3).
47 RFC977: Network News Transfer Protocol (NNTP).
48 RFC2076: Common Internet Message Headers.
49 RFC2045 , RFC2046 , RFC2047 , RFC2048 & RFC2049: Multipurpose Internet Mail Extensions (MIME).
50
51 To understand the return types from the imap functions take a look at the mail.h file in the mime c-klient library
52 found here: ftp://ftp.cac.washington.edu/imap
53 */
54
55 // include_once( "ezmail/classes/ezmail.php" );
56 // include_once( "ezmail/classes/ezmailfunctions.php" );
57 // include_once( "ezmail/classes/ezmailfilterrule.php" );
58 // include_once( "classes/ezhttptool.php" );
59
60 class eZMailAccount
61 {
65 function __construct( $id="" )
66 {
67 $this->ServerType = 0;
68
69 if ( $id != "" )
70 {
71 $this->ID = $id;
72 $this->get( $this->ID );
73 }
74 }
75
79 function delete( $id = -1 )
80 {
81 $db =& eZDB::globalDatabase();
82
83 if ( $id == -1 )
84 {
85 $db->query( "DELETE FROM eZMail_Account WHERE ID='$this->ID'" );
86 }
87 else
88 {
89 $db->query( "DELETE FROM eZMail_Account WHERE ID='$id'" );
90 }
91 return true;
92 }
93
97 function store()
98 {
99 $db =& eZDB::globalDatabase();
100 $name = $db->escapeString( $this->Name );
101 $loginname = $db->escapeString( $this->LoginName );
102 $password = $db->escapeString( $this->Password );
103 $server = $db->escapeString( $this->Server );
104 $db->begin();
105 if ( !isset( $this->ID ) )
106 {
107 $db->lock( "eZMail_Account" );
108 $nextID = $db->nextID( "eZMail_Account", "ID" );
109 $result = $db->query( "INSERT INTO eZMail_Account ( ID, UserID, Name, LoginName, Password,
110 Server, DeleteFromServer, IsActive, ServerType, ServerPort )
111 VALUES (
112 '$nextID',
113 '$this->UserID',
114 '$name',
115 '$loginname',
116 '$password',
117 '$server',
118 '$this->DeleteFromServer',
119 '$this->IsActive',
120 '$this->ServerType',
121 '$this->ServerPort' )
122 " );
123 $db->unlock();
124 $this->ID = $nextID;
125 }
126 else
127 {
128 $result = $db->query( "UPDATE eZMail_Account SET
129 UserID='$this->UserID',
130 Name='$name',
131 LoginName='$loginname',
132 Password='$password',
133 Server='$server',
134 DeleteFromServer='$this->DeleteFromServer',
135 IsActive='$this->IsActive',
136 ServerType='$this->ServerType',
137 ServerPort='$this->ServerPort'
138 WHERE ID='$this->ID'
139 " );
140 }
141 if ( $result == false )
142 $db->rollback( );
143 else
144 $db->commit();
145
146 return true;
147 }
148
152 function get( $id="" )
153 {
154 $ret = false;
155
156 if ( $id != "" )
157 {
158 $db =& eZDB::globalDatabase();
159 $db->array_query( $account_array, "SELECT * FROM eZMail_Account WHERE ID='$id'" );
160 if ( count( $account_array ) > 1 )
161 {
162 die( "Error: Mail accounts with the same ID was found in the database. This should not happen." );
163 }
164 else if ( count( $account_array ) == 1 )
165 {
166
167 $this->ID =& $account_array[0][$db->fieldName( "ID" )];
168 $this->UserID =& $account_array[0][$db->fieldName( "UserID" )];
169 $this->Name =& $account_array[0][$db->fieldName( "Name" )];
170 $this->LoginName =& $account_array[0][$db->fieldName( "LoginName" )];
171 $this->Password =& $account_array[0][$db->fieldName( "Password" )];
172 $this->Server =& $account_array[0][$db->fieldName( "Server" )];
173 $this->DeleteFromServer =& $account_array[0][$db->fieldName( "DeleteFromServer" )];
174 $this->IsActive =& $account_array[0][$db->fieldName( "IsActive" )];
175 $this->ServerType =& $account_array[0][$db->fieldName( "ServerType" )];
176 $this->ServerPort =& $account_array[0][$db->fieldName( "ServerPort" )];
177
178 $ret = true;
179 }
180 }
181 return $ret;
182 }
183
184 /*
185 Returns the ID of this object.
186 */
187 function id()
188 {
189 return $this->ID;
190 }
191
195 function userID()
196 {
197 return $this->UserID;
198 }
199
203 function setUserID( $value )
204 {
205 $this->UserID = $value;
206 }
207
211 function setUser( $user )
212 {
213 if ( is_a( $user, "eZUser" ) )
214 $this->UserID = $user->id();
215 }
216
220 function name()
221 {
222 return $this->Name;
223 }
224
228 function setName( $value )
229 {
230 $this->Name = $value;
231 }
232
236 function loginName()
237 {
238 return $this->LoginName;
239 }
240
244 function setLoginName( $value )
245 {
246 $this->LoginName = $value;
247 }
248
249
253 function password()
254 {
255 return $this->Password;
256 }
257
262 function setPassword( $value )
263 {
264 $this->Password = $value;
265 }
266
270 function server()
271 {
272 return $this->Server;
273 }
274
278 function setServer( $value )
279 {
280 $this->Server = $value;
281 }
282
286 function serverPort()
287 {
288 return $this->ServerPort;
289 }
290
294 function setServerPort( $value )
295 {
296 $this->ServerPort = $value;
297 }
298
302 function deleteFromServer()
303 {
304 return $this->DeleteFromServer;
305 }
306
311 function setDeleteFromServer( $value )
312 {
313 $this->DeleteFromServer = $value;
314 }
315
319 function isActive()
320 {
321 return $this->IsActive;
322 }
323
327 function setIsActive( $value )
328 {
329 $this->IsActive = $value;
330 }
331
335 function serverType()
336 {
337 return $this->ServerType;
338 }
339
343 function setServerType( $value )
344 {
345 $this->ServerType = $value;
346 }
347
353 static public function isOwner( $user, $accountID )
354 {
355 if ( is_a( $user, "eZUser" ) )
356 $user = $user->id();
357
358 $db =& eZDB::globalDatabase();
359 $db->query_single( $res, "SELECT UserID from eZMail_Account WHERE ID='$accountID'" );
360
361 if ( is_array( $res ) && $res[$db->fieldName("UserID")] == $user )
362 return true;
363
364 return false;
365 }
366
372 static public function getByUser( $user )
373 {
374 if ( is_a( $user, "eZUser" ) )
375 $user = $user->id();
376
377 $db =& eZDB::globalDatabase();
378
379 $return_array = array();
380 $account_array = array();
381
382 $db->array_query( $account_array, "SELECT ID FROM eZMail_Account WHERE UserID='$user'" );
383
384 for ( $i = 0; $i < count( $account_array ); $i++ )
385 {
386 $return_array[$i] = new eZMailAccount( $account_array[$i][$db->fieldName( "ID" )] );
387 }
388
389 return $return_array;
390 }
391
396 function checkMail()
397 {
398 $user =& eZUser::currentUser();
399 //$server = "{" . $this->Server . "/pop3:" .$this->ServerPort ."}";
400 $server = "{" . $this->Server . "/imap:" .$this->ServerPort ."}";
401 $mbox = imap_open( $server, $this->LoginName, $this->Password, OP_HALFOPEN);
402 if ( $mbox == false )
403 {
404 $errorMsg = rawurlencode( imap_last_error() );
405 eZHTTPTool::header( "Location: /error/error?Info=$errorMsg" );
406 exit();
407 }
408
409 //debug!!!!
410 // $struct = imap_fetchstructure( $mbox, 1 );
411 // echo "<pre>"; print_r( $struct ); echo "</pre>";
412 // exit;
413
414 // get the inbox... we will be adding mail to this.
415 $inbox = eZMailFolder::getSpecialFolder( INBOX );
416 $filters = new eZMailFilter();
417
418 $num = imap_num_msg( $mbox ); // fetch numbers of all new mails
419 for ( $i = 1; $i <= $num; $i++ ) // go through each mail in inbox
420 {
421 $headerinfo = imap_header( $mbox, $i ); // fetch mail headers
422 if ( !eZMail::isDownloaded( $headerinfo->message_id, $user->id() ) ) // check if allready downloaded
423 {
424 $mail = new eZMail();
425 $mail->setOwner( $user );
426 $mail->setStatus( UNREAD );
427 $mail->setUDate( $headerinfo->udate );
428
429 getHeaders( $mail, $mbox, $i ); // fetch header information
430 $mail->store(); // to get ID
431
432 set_time_limit( 20 );
433 $mailstructure = imap_fetchstructure( $mbox, $i );
434 disectThisPart( $mailstructure, "1", $mbox, $i, $mail );
435 $mail->setSize( $mailstructure->bytes );
436
437 $mail->store();
438 $mail->markAsDownloaded();
439 $inbox->addMail( $mail ); // safety for now while we debug the filters
440 $filters->runFilters( $mail );
441
442 if ( $this->DeleteFromServer == true )
443 imap_delete( $mbox, $i );
444 }
445 }
446
447 // $headers = imap_headers( $mbox );
448 // print("<pre>"); print_r( $headers ); print("</pre>" );
449 imap_close( $mbox, CL_EXPUNGE );
450 }
451
452
457 function getNewMail( $LoginName, $Password, $ServerName, $ServerPort = 110 )
458 {
459 $server = "{" . $ServerName . "/pop3:" .$ServerPort ."}";
460 $mbox = imap_open( $server, $LoginName, $Password, OP_HALFOPEN );
461 if ( $mbox == false )
462 {
463 $errorMsg = rawurlencode( imap_last_error() );
464 eZHTTPTool::header( "Location: /error/error?Info=$errorMsg" );
465 exit();
466 }
467 $ret_array = array();
468 // get the inbox... we will be adding mail to this.
469 // $inbox = eZMailFolder::getSpecialFolder( INBOX );
470 // $filters = new eZMailFilter();
471
472 // fetch numbers of all new mails
473 $num = imap_num_msg( $mbox );
474
475 // go through each mail in inbox
476 for ( $i = 1; $i <= $num; $i++ )
477 {
478 // fetch mail headers
479 $headerinfo = imap_header( $mbox, $i );
480
481 $mail = new eZMail();
482 $mail->setOwner( $user );
483 $mail->setStatus( UNREAD );
484 $mail->setUDate( $headerinfo->udate );
485
486 getHeaders( $mail, $mbox, $i ); // fetch header information
487 $mail->store(); // to get ID
488
489 $mailstructure = imap_fetchstructure( $mbox, $i );
490 disectThisPart( $mailstructure, "1", $mbox, $i, $mail );
491 $mail->setSize( $mailstructure->bytes );
492
493 $mail->store();
494 $mail->markAsDownloaded();
495 $ret_array[] = $mail;
496 imap_delete( $mbox, $i );
497 }
498
499 // $headers = imap_headers( $mbox );
500 // print("<pre>"); print_r( $headers ); print("</pre>" );
501 imap_close( $mbox, CL_EXPUNGE );
502 return $ret_array;
503 }
504
505
506 var $ID;
507 var $UserID;
508 var $Name;
509 var $LoginName;
510 var $Password;
511 var $Server;
512 var $ServerPort;
513 var $DeleteFromServer;
514 var $IsActive;
515 var $ServerType;
516 }
517
518 ?>
$i
$i
Definition: admin/adlist.php:91
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZMailAccount
Definition: ezmailaccount.php:61
eZMailAccount\isOwner
static isOwner( $user, $accountID)
Definition: ezmailaccount.php:353
eZMailAccount\setName
setName( $value)
Definition: ezmailaccount.php:228
eZMailAccount\serverPort
serverPort()
Definition: ezmailaccount.php:286
eZMailAccount\checkMail
checkMail()
Definition: ezmailaccount.php:396
eZMailAccount\setIsActive
setIsActive( $value)
Definition: ezmailaccount.php:327
eZMailAccount\$Password
$Password
Definition: ezmailaccount.php:510
eZMailAccount\setServer
setServer( $value)
Definition: ezmailaccount.php:278
eZMailAccount\deleteFromServer
deleteFromServer()
Definition: ezmailaccount.php:302
eZMailAccount\setServerType
setServerType( $value)
Definition: ezmailaccount.php:343
eZMailAccount\userID
userID()
Definition: ezmailaccount.php:195
eZMailAccount\loginName
loginName()
Definition: ezmailaccount.php:236
eZMailAccount\$ServerType
$ServerType
Definition: ezmailaccount.php:515
eZMailAccount\$LoginName
$LoginName
Definition: ezmailaccount.php:509
eZMailAccount\isActive
isActive()
Definition: ezmailaccount.php:319
eZMailAccount\$ID
$ID
Definition: ezmailaccount.php:506
eZMailAccount\server
server()
Definition: ezmailaccount.php:270
eZMailAccount\store
store()
Definition: ezmailaccount.php:97
eZMailAccount\setUserID
setUserID( $value)
Definition: ezmailaccount.php:203
eZMailAccount\$ServerPort
$ServerPort
Definition: ezmailaccount.php:512
eZMailAccount\$Name
$Name
Definition: ezmailaccount.php:508
eZMailAccount\setLoginName
setLoginName( $value)
Definition: ezmailaccount.php:244
eZMailAccount\__construct
__construct( $id="")
Definition: ezmailaccount.php:65
eZMailAccount\serverType
serverType()
Definition: ezmailaccount.php:335
eZMailAccount\name
name()
Definition: ezmailaccount.php:220
eZMailAccount\$IsActive
$IsActive
Definition: ezmailaccount.php:514
eZMailAccount\setPassword
setPassword( $value)
Definition: ezmailaccount.php:262
eZMailAccount\setServerPort
setServerPort( $value)
Definition: ezmailaccount.php:294
eZMailAccount\setDeleteFromServer
setDeleteFromServer( $value)
Definition: ezmailaccount.php:311
eZMailAccount\password
password()
Definition: ezmailaccount.php:253
eZMailAccount\$DeleteFromServer
$DeleteFromServer
Definition: ezmailaccount.php:513
eZMailAccount\$Server
$Server
Definition: ezmailaccount.php:511
eZMailAccount\id
id()
Definition: ezmailaccount.php:187
eZMailAccount\$UserID
$UserID
Definition: ezmailaccount.php:507
eZMailAccount\getByUser
static getByUser( $user)
Definition: ezmailaccount.php:372
eZMailAccount\getNewMail
getNewMail( $LoginName, $Password, $ServerName, $ServerPort=110)
Definition: ezmailaccount.php:457
eZMailAccount\setUser
setUser( $user)
Definition: ezmailaccount.php:211
eZMailFilter
Definition: ezmailfilterrule.php:492
eZMailFolder\getSpecialFolder
static getSpecialFolder( $specialType, $user=false)
Definition: ezmailfolder.php:477
eZMail
Definition: ezmail.php:57
eZMail\isDownloaded
static isDownloaded( $mailident, $userID)
Definition: ezmail.php:628
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$filters
foreach( $accounts as $account) $filters
Definition: configure.php:173
$db
$db
Definition: ezarticle/user/authorlist.php:53
$server
$server
Definition: ezarticle/xmlrpc/xmlrpcserver.php:63
$mail
$mail
Definition: ezbulkmail/admin/maillist.php:61
UNREAD
const UNREAD
Definition: ezmail.php:50
INBOX
const INBOX
Definition: ezmailfolder.php:43
disectThisPart
disectThisPart( $this_part, $part_no, $mbox, $msgnum, &$mail, $level=0)
Definition: ezmailfunctions.php:92
getHeaders
getHeaders(&$mail, $imap_stream, $msgno)
Definition: ezmailfunctions.php:40
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
exit
exit
Definition: folder.php:81
Password
</td ></tr >< tr >< td style="color:<?= isset( $error['password1'] ) ?> Password
Definition: step1.php:146
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.