source: trunk/emailadmin/inc/class.bo.inc.php @ 1523

Revision 1523, 12.7 KB checked in by wmerlotto, 15 years ago (diff)

Ticket #690 - emailadmin alterado permitindo a integração, ou não, com anti-spam

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[2]1<?php
2        /***************************************************************************\
3        * eGroupWare                                                                *
4        * http://www.egroupware.org                                                 *
5        * http://www.linux-at-work.de                                               *
6        * Written by : Lars Kneschke [lkneschke@linux-at-work.de]                   *
7        * -------------------------------------------------                         *
8        * This program is free software; you can redistribute it and/or modify it   *
9        * under the terms of the GNU General Public License as published by the     *
10        * Free Software Foundation; either version 2 of the License, or (at your    *
11        * option) any later version.                                                *
12        \***************************************************************************/
13
14        class bo
15        {
16                var $sessionData;
17                var $LDAPData;
18               
19                var $SMTPServerType = array();          // holds a list of config options
20               
21                var $imapClass;                         // holds the imap/pop3 class
22                var $smtpClass;                         // holds the smtp class
23
24                var $public_functions = array
25                (
26                        'getFieldNames'         => True,
27                        'getLDAPStorageData'    => True,
28                        'getLocals'             => True,
29                        'getProfile'            => True,
30                        'getProfileList'        => True,
31                        'getRcptHosts'          => True,
32                        'getSMTPServerTypes'    => True
33                );
34
35                function bo($_profileID=-1)
36                {
37                        $this->soemailadmin = CreateObject('emailadmin.so');
38                       
39                        $this->SMTPServerType = array(
40                                '1'     => array(
41                                        'fieldNames'    => array(
42                                                'smtpServer',
43                                                'smtpPort',
44                                                'smtpAuth',
45                                                'smtpType'
46                                        ),
47                                        'description'   => lang('standard SMTP-Server'),
48                                        'classname'     => 'defaultsmtp'
49                                ),
50                                '2'     => array(
51                                        'fieldNames'    => array(
52                                                'smtpServer',
53                                                'smtpPort',
54                                                'smtpAuth',
55                                                'smtpType',
56                                                'smtpLDAPServer',
57                                                'smtpLDAPAdminDN',
58                                                'smtpLDAPAdminPW',
59                                                'smtpLDAPBaseDN',
60                                                'smtpLDAPUseDefault'
61                                        ),
62                                        'description'   => lang('Postfix with LDAP'),
63                                        'classname'     => 'postfixldap'
64                                )
65                        );
66
67                        $this->IMAPServerType = array(
68                                '1'     => array(
69                                        'fieldNames'    => array(
70                                                'imapServer',
71                                                'imapPort',
72                                                'imapType',
73                                                'imapLoginType',
74                                                'imapTLSEncryption',
75                                                'imapTLSAuthentication',
76                                                'imapoldcclient'
77                                        ),
78                                        'description'   => lang('standard POP3 server'),
79                                        'protocol'      => 'pop3',
80                                        'classname'     => 'defaultpop'
81                                ),
82                                '2'     => array(
83                                        'fieldNames'    => array(
84                                                'imapServer',
85                                                'imapPort',
86                                                'imapType',
87                                                'imapLoginType',
88                                                'imapTLSEncryption',
89                                                'imapTLSAuthentication',
90                                                'imapoldcclient'
91                                        ),
92                                        'description'   => lang('standard IMAP server'),
93                                        'protocol'      => 'imap',
94                                        'classname'     => 'defaultimap'
95                                ),
96                                '3'     => array(
97                                        'fieldNames'    => array(
98                                                'imapServer',
99                                                'imapPort',
100                                                'imapDelimiter',
101                                                'imapType',
102                                                'imapLoginType',
103                                                'imapTLSEncryption',
104                                                'imapTLSAuthentication',
105                                                'imapoldcclient',
106                                                'imapEnableCyrusAdmin',
107                                                'imapAdminUsername',
108                                                'imapAdminPW',
109                                                'imapEnableSieve',
110                                                'imapSieveServer',
[187]111                                                'imapSievePort',
[1523]112                                                'imapCreateSpamFolder',
113                                                'imapCyrusUserPostSpam',
[187]114                                                'imapDefaultTrashFolder',
115                                                'imapDefaultSentFolder',
116                                                'imapDefaultDraftsFolder',
117                                                'imapDefaultSpamFolder'
[2]118                                        ),
119                                        'description'   => lang('Cyrus IMAP Server'),
120                                        'protocol'      => 'imap',
121                                        'classname'     => 'cyrusimap'
122                                )
123                        );
124                       
125                        $this->restoreSessionData();
126                       
127                        if($_profileID >= 0)
128                        {
129                                $this->profileID        = $_profileID;
130                       
131                                $this->profileData      = $this->getProfile($_profileID);
132                       
133                                $this->imapClass        = $this->IMAPServerType[$this->profileData['imapType']]['classname'];
134                                $this->smtpClass        = $this->SMTPServerType[$this->profileData['smtpType']]['classname'];
135                        }
136                }
137               
138                function addAccount($_hookValues)
139                {
140                        if (!empty($this->imapClass))
141                        {
142                                ExecMethod("emailadmin.".$this->imapClass.".addAccount",$_hookValues,3,$this->profileData);
143                        }
144                       
145                        if (!empty($this->smtpClass))
146                        {
147                                ExecMethod("emailadmin.".$this->smtpClass.".addAccount",$_hookValues,3,$this->profileData);
148                        }
149                }
150               
151                function deleteAccount($_hookValues)
152                {
153                        if (!empty($this->imapClass))
154                        {
155                                ExecMethod("emailadmin.".$this->imapClass.".deleteAccount",$_hookValues,3,$this->profileData);
156                        }
157
158                        if (!empty($this->smtpClass))
159                        {
160                                ExecMethod("emailadmin.".$this->smtpClass.".deleteAccount",$_hookValues,3,$this->profileData);
161                        }
162                }
163               
164                function deleteProfile($_profileID)
165                {
166                        $this->soemailadmin->deleteProfile($_profileID);
167                }
168               
169                function encodeHeader($_string, $_encoding='q')
170                {
171                        switch($_encoding)
172                        {
173                                case "q":
174                                        if(!preg_match("/[\x80-\xFF]/",$_string))
175                                        {
176                                                // nothing to quote, only 7 bit ascii
177                                                return $_string;
178                                        }
179                                       
180                                        $string = imap_8bit($_string);
181                                        $stringParts = explode("=\r\n",$string);
182                                        while(list($key,$value) = each($stringParts))
183                                        {
184                                                if(!empty($retString)) $retString .= " ";
185                                                $value = str_replace(" ","_",$value);
186                                                // imap_8bit does not convert "?"
187                                                // it does not need, but it should
188                                                $value = str_replace("?","=3F",$value);
189                                                $retString .= "=?".strtoupper($this->displayCharset)."?Q?".$value."?=";
190                                        }
191                                        #exit;
192                                        return $retString;
193                                        break;
194                                default:
195                                        return $_string;
196                        }
197                }
198
199                function getAccountEmailAddress($_accountName, $_profileID)
200                {
201                        $profileData    = $this->getProfile($_profileID);
202                       
203                        $smtpClass      = $this->SMTPServerType[$profileData['smtpType']]['classname'];
204
205                        return empty($smtpClass) ? False : ExecMethod("emailadmin.$smtpClass.getAccountEmailAddress",$_accountName,3,$profileData);
206                }
207               
208                function getFieldNames($_serverTypeID, $_class)
209                {
210                        switch($_class)
211                        {
212                                case 'imap':
213                                        return $this->IMAPServerType[$_serverTypeID]['fieldNames'];
214                                        break;
215                                case 'smtp':
216                                        return $this->SMTPServerType[$_serverTypeID]['fieldNames'];
217                                        break;
218                        }
219                }
220               
221#               function getIMAPClass($_profileID)
222#               {
223#                       if(!is_object($this->imapClass))
224#                       {
225#                               $profileData            = $this->getProfile($_profileID);
226#                               $this->imapClass        = CreateObject('emailadmin.cyrusimap',$profileData);
227#                       }
228#                       
229#                       return $this->imapClass;
230#               }
231               
232                function getIMAPServerTypes()
233                {
234                        foreach($this->IMAPServerType as $key => $value)
235                        {
236                                $retData[$key]['description']   = $value['description'];
237                                $retData[$key]['protocol']      = $value['protocol'];
238                        }
239                       
240                        return $retData;
241                }
242               
243                function getLDAPStorageData($_serverid)
244                {
245                        $storageData = $this->soemailadmin->getLDAPStorageData($_serverid);
246                        return $storageData;
247                }
248               
249                function getMailboxString($_folderName)
250                {
251                        if (!empty($this->imapClass))
252                        {
253                                return ExecMethod("emailadmin.".$this->imapClass.".getMailboxString",$_folderName,3,$this->profileData);
254                        }
255                        else
256                        {
257                                return false;
258                        }
259                }
260
261                function getProfile($_profileID)
262                {
263                        $profileData = $this->soemailadmin->getProfileList($_profileID);
264                        $fieldNames = $this->SMTPServerType[$profileData[0]['smtpType']]['fieldNames'];
265                        $fieldNames = array_merge($fieldNames, $this->IMAPServerType[$profileData[0]['imapType']]['fieldNames']);
266                        $fieldNames[] = 'description';
267                        $fieldNames[] = 'defaultDomain';
268                        $fieldNames[] = 'profileID';
269                        $fieldNames[] = 'organisationName';
270                        $fieldNames[] = 'userDefinedAccounts';
271                       
272                        return $this->soemailadmin->getProfile($_profileID, $fieldNames);
273                }
274               
275                function getProfileList($_profileID='')
276                {
277                        $profileList = $this->soemailadmin->getProfileList($_profileID);
278                        return $profileList;
279                }
280               
281#               function getSMTPClass($_profileID)
282#               {
283#                       if(!is_object($this->smtpClass))
284#                       {
285#                               $profileData            = $this->getProfile($_profileID);
286#                               $this->smtpClass        = CreateObject('emailadmin.postfixldap',$profileData);
287#                       }
288#                       
289#                       return $this->smtpClass;
290#               }
291               
292                function getSMTPServerTypes()
293                {
294                        foreach($this->SMTPServerType as $key => $value)
295                        {
296                                $retData[$key] = $value['description'];
297                        }
298                       
299                        return $retData;
300                }
301               
302                function getUserData($_accountID, $_usecache)
303                {
304                        if ($_usecache)
305                        {
306                                $userData = $this->userSessionData[$_accountID];
307                        }
308                        else
309                        {
310                                $userData = $this->soemailadmin->getUserData($_accountID);
311                                $bofelamimail = CreateObject('felamimail.bofelamimail');
312                                $bofelamimail->openConnection('','',true);
313                                $userQuota =
314                                        $bofelamimail->imapGetQuota($GLOBALS['phpgw']->accounts->id2name($_accountID));
315                                if(is_array($userQuota))
316                                {
317                                        $userData['quotaLimit'] = $userQuota['limit'];
318                                }
319                                $bofelamimail->closeConnection();
320                                $this->userSessionData[$_accountID] = $userData;
321                                $this->saveSessionData();
322                        }
323                        return $userData;
324                }
325
326                function restoreSessionData()
327                {
328                        global $phpgw;
329               
330                        $this->sessionData = $phpgw->session->appsession('session_data');
331                        $this->userSessionData = $phpgw->session->appsession('user_session_data');
332                       
333                        #while(list($key, $value) = each($this->userSessionData))
334                        #{
335                        #       print "++ $key: $value<br>";
336                        #}
337                        #print "restored Session<br>";
338                }
339               
340                function saveProfile($_globalSettings, $_smtpSettings, $_imapSettings)
341                {
342                        if(!isset($_globalSettings['profileID']))
343                        {
344                                $this->soemailadmin->addProfile($_globalSettings, $_smtpSettings, $_imapSettings);
345                        }
346                        else
347                        {
348                                $this->soemailadmin->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings);
349                        }
350                }
351               
352                function saveSessionData()
353                {
354                        global $phpgw;
355                       
356                        $phpgw->session->appsession('session_data','',$this->sessionData);
357                        $phpgw->session->appsession('user_session_data','',$this->userSessionData);
358                }
359               
360                function saveUserData($_accountID, $_formData, $_boAction)
361                {
362                        $this->userSessionData[$_accountID]['mailLocalAddress']         = $_formData["mailLocalAddress"];
363                        $this->userSessionData[$_accountID]['accountStatus']            = $_formData["accountStatus"];
364                        $this->userSessionData[$_accountID]['deliveryMode']             = $_formData["deliveryMode"];
365                        $this->userSessionData[$_accountID]['qmailDotMode']             = $_formData["qmailDotMode"];
366                        $this->userSessionData[$_accountID]['deliveryProgramPath']      = $_formData["deliveryProgramPath"];
367                        $this->userSessionData[$_accountID]['quotaLimit']               = $_formData["quotaLimit"];
368
369                        switch ($_boAction)
370                        {
371                                case 'add_mailAlternateAddress':
372                                        if (is_array($this->userSessionData[$_accountID]['mailAlternateAddress']))
373                                        {
374                                                $count = count($this->userSessionData[$_accountID]['mailAlternateAddress']);
375                                        }
376                                        else
377                                        {
378                                                $count = 0;
379                                                $this->userSessionData[$_accountID]['mailAlternateAddress'] = array();
380                                        }
381                                       
382                                        $this->userSessionData[$_accountID]['mailAlternateAddress'][$count] =
383                                                $_formData['add_mailAlternateAddress'];
384                                               
385                                        $this->saveSessionData();
386                                       
387                                        break;
388                                       
389                                case 'remove_mailAlternateAddress':
390                                        $i=0;
391                                       
392                                        while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailAlternateAddress']))
393                                        {
394                                                #print ".. $key: $value<br>";
395                                                if ($key != $_formData['remove_mailAlternateAddress'])
396                                                {
397                                                        $newMailAlternateAddress[$i]=$value;
398                                                        #print "!! $i: $value<br>";
399                                                        $i++;
400                                                }
401                                        }
402                                        $this->userSessionData[$_accountID]['mailAlternateAddress'] = $newMailAlternateAddress;
403                                       
404                                        $this->saveSessionData();
405
406                                        break;
407                                       
408                                case 'add_mailRoutingAddress':
409                                        if (is_array($this->userSessionData[$_accountID]['mailRoutingAddress']))
410                                        {
411                                                $count = count($this->userSessionData[$_accountID]['mailRoutingAddress']);
412                                        }
413                                        else
414                                        {
415                                                $count = 0;
416                                                $this->userSessionData[$_accountID]['mailRoutingAddress'] = array();
417                                        }
418                                       
419                                        $this->userSessionData[$_accountID]['mailRoutingAddress'][$count] =
420                                                $_formData['add_mailRoutingAddress'];
421                                               
422                                        $this->saveSessionData();
423
424                                        break;
425                                       
426                                case 'remove_mailRoutingAddress':
427                                        $i=0;
428                                       
429                                        while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailRoutingAddress']))
430                                        {
431                                                if ($key != $_formData['remove_mailRoutingAddress'])
432                                                {
433                                                        $newMailRoutingAddress[$i]=$value;
434                                                        $i++;
435                                                }
436                                        }
437                                        $this->userSessionData[$_accountID]['mailRoutingAddress'] = $newMailRoutingAddress;
438                                       
439                                        $this->saveSessionData();
440
441                                        break;
442                                       
443                                case 'save':
444                                        $this->soemailadmin->saveUserData(
445                                                $_accountID,
446                                                $this->userSessionData[$_accountID]);
447                                        $bofelamimail = CreateObject('felamimail.bofelamimail');
448                                        $bofelamimail->openConnection('','',true);
449                                        $bofelamimail->imapSetQuota($GLOBALS['phpgw']->accounts->id2name($_accountID),
450                                                                    $this->userSessionData[$_accountID]['quotaLimit']);
451                                        $bofelamimail->closeConnection();
452                                        $GLOBALS['phpgw']->accounts->cache_invalidate($_accountID);
453                                       
454                                       
455                                        break;
456                        }
457                }
458
459                function updateAccount($_hookValues)
460                {
461                        if (!empty($this->imapClass))
462                        {
463                                ExecMethod("emailadmin.".$this->imapClass.".updateAccount",$_hookValues,3,$this->profileData);
464                        }
465
466                        if (!empty($this->smtpClass))
467                        {
468                                ExecMethod("emailadmin.".$this->smtpClass.".updateAccount",$_hookValues,3,$this->profileData);
469                        }
470                }
471               
472        }
473?>
Note: See TracBrowser for help on using the repository browser.