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

Revision 187, 12.7 KB checked in by niltonneto, 16 years ago (diff)
  • 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',
112                                                'imapDefaultTrashFolder',
113                                                'imapDefaultSentFolder',
114                                                'imapDefaultDraftsFolder',
115                                                'imapDefaultSpamFolder'
[2]116                                        ),
117                                        'description'   => lang('Cyrus IMAP Server'),
118                                        'protocol'      => 'imap',
119                                        'classname'     => 'cyrusimap'
120                                )
121                        );
122                       
123                        $this->restoreSessionData();
124                       
125                        if($_profileID >= 0)
126                        {
127                                $this->profileID        = $_profileID;
128                       
129                                $this->profileData      = $this->getProfile($_profileID);
130                       
131                                $this->imapClass        = $this->IMAPServerType[$this->profileData['imapType']]['classname'];
132                                $this->smtpClass        = $this->SMTPServerType[$this->profileData['smtpType']]['classname'];
133                        }
134                }
135               
136                function addAccount($_hookValues)
137                {
138                        if (!empty($this->imapClass))
139                        {
140                                ExecMethod("emailadmin.".$this->imapClass.".addAccount",$_hookValues,3,$this->profileData);
141                        }
142                       
143                        if (!empty($this->smtpClass))
144                        {
145                                ExecMethod("emailadmin.".$this->smtpClass.".addAccount",$_hookValues,3,$this->profileData);
146                        }
147                }
148               
149                function deleteAccount($_hookValues)
150                {
151                        if (!empty($this->imapClass))
152                        {
153                                ExecMethod("emailadmin.".$this->imapClass.".deleteAccount",$_hookValues,3,$this->profileData);
154                        }
155
156                        if (!empty($this->smtpClass))
157                        {
158                                ExecMethod("emailadmin.".$this->smtpClass.".deleteAccount",$_hookValues,3,$this->profileData);
159                        }
160                }
161               
162                function deleteProfile($_profileID)
163                {
164                        $this->soemailadmin->deleteProfile($_profileID);
165                }
166               
167                function encodeHeader($_string, $_encoding='q')
168                {
169                        switch($_encoding)
170                        {
171                                case "q":
172                                        if(!preg_match("/[\x80-\xFF]/",$_string))
173                                        {
174                                                // nothing to quote, only 7 bit ascii
175                                                return $_string;
176                                        }
177                                       
178                                        $string = imap_8bit($_string);
179                                        $stringParts = explode("=\r\n",$string);
180                                        while(list($key,$value) = each($stringParts))
181                                        {
182                                                if(!empty($retString)) $retString .= " ";
183                                                $value = str_replace(" ","_",$value);
184                                                // imap_8bit does not convert "?"
185                                                // it does not need, but it should
186                                                $value = str_replace("?","=3F",$value);
187                                                $retString .= "=?".strtoupper($this->displayCharset)."?Q?".$value."?=";
188                                        }
189                                        #exit;
190                                        return $retString;
191                                        break;
192                                default:
193                                        return $_string;
194                        }
195                }
196
197                function getAccountEmailAddress($_accountName, $_profileID)
198                {
199                        $profileData    = $this->getProfile($_profileID);
200                       
201                        $smtpClass      = $this->SMTPServerType[$profileData['smtpType']]['classname'];
202
203                        return empty($smtpClass) ? False : ExecMethod("emailadmin.$smtpClass.getAccountEmailAddress",$_accountName,3,$profileData);
204                }
205               
206                function getFieldNames($_serverTypeID, $_class)
207                {
208                        switch($_class)
209                        {
210                                case 'imap':
211                                        return $this->IMAPServerType[$_serverTypeID]['fieldNames'];
212                                        break;
213                                case 'smtp':
214                                        return $this->SMTPServerType[$_serverTypeID]['fieldNames'];
215                                        break;
216                        }
217                }
218               
219#               function getIMAPClass($_profileID)
220#               {
221#                       if(!is_object($this->imapClass))
222#                       {
223#                               $profileData            = $this->getProfile($_profileID);
224#                               $this->imapClass        = CreateObject('emailadmin.cyrusimap',$profileData);
225#                       }
226#                       
227#                       return $this->imapClass;
228#               }
229               
230                function getIMAPServerTypes()
231                {
232                        foreach($this->IMAPServerType as $key => $value)
233                        {
234                                $retData[$key]['description']   = $value['description'];
235                                $retData[$key]['protocol']      = $value['protocol'];
236                        }
237                       
238                        return $retData;
239                }
240               
241                function getLDAPStorageData($_serverid)
242                {
243                        $storageData = $this->soemailadmin->getLDAPStorageData($_serverid);
244                        return $storageData;
245                }
246               
247                function getMailboxString($_folderName)
248                {
249                        if (!empty($this->imapClass))
250                        {
251                                return ExecMethod("emailadmin.".$this->imapClass.".getMailboxString",$_folderName,3,$this->profileData);
252                        }
253                        else
254                        {
255                                return false;
256                        }
257                }
258
259                function getProfile($_profileID)
260                {
261                        $profileData = $this->soemailadmin->getProfileList($_profileID);
262                        $fieldNames = $this->SMTPServerType[$profileData[0]['smtpType']]['fieldNames'];
263                        $fieldNames = array_merge($fieldNames, $this->IMAPServerType[$profileData[0]['imapType']]['fieldNames']);
264                        $fieldNames[] = 'description';
265                        $fieldNames[] = 'defaultDomain';
266                        $fieldNames[] = 'profileID';
267                        $fieldNames[] = 'organisationName';
268                        $fieldNames[] = 'userDefinedAccounts';
269                       
270                        return $this->soemailadmin->getProfile($_profileID, $fieldNames);
271                }
272               
273                function getProfileList($_profileID='')
274                {
275                        $profileList = $this->soemailadmin->getProfileList($_profileID);
276                        return $profileList;
277                }
278               
279#               function getSMTPClass($_profileID)
280#               {
281#                       if(!is_object($this->smtpClass))
282#                       {
283#                               $profileData            = $this->getProfile($_profileID);
284#                               $this->smtpClass        = CreateObject('emailadmin.postfixldap',$profileData);
285#                       }
286#                       
287#                       return $this->smtpClass;
288#               }
289               
290                function getSMTPServerTypes()
291                {
292                        foreach($this->SMTPServerType as $key => $value)
293                        {
294                                $retData[$key] = $value['description'];
295                        }
296                       
297                        return $retData;
298                }
299               
300                function getUserData($_accountID, $_usecache)
301                {
302                        if ($_usecache)
303                        {
304                                $userData = $this->userSessionData[$_accountID];
305                        }
306                        else
307                        {
308                                $userData = $this->soemailadmin->getUserData($_accountID);
309                                $bofelamimail = CreateObject('felamimail.bofelamimail');
310                                $bofelamimail->openConnection('','',true);
311                                $userQuota =
312                                        $bofelamimail->imapGetQuota($GLOBALS['phpgw']->accounts->id2name($_accountID));
313                                if(is_array($userQuota))
314                                {
315                                        $userData['quotaLimit'] = $userQuota['limit'];
316                                }
317                                $bofelamimail->closeConnection();
318                                $this->userSessionData[$_accountID] = $userData;
319                                $this->saveSessionData();
320                        }
321                        return $userData;
322                }
323
324                function restoreSessionData()
325                {
326                        global $phpgw;
327               
328                        $this->sessionData = $phpgw->session->appsession('session_data');
329                        $this->userSessionData = $phpgw->session->appsession('user_session_data');
330                       
331                        #while(list($key, $value) = each($this->userSessionData))
332                        #{
333                        #       print "++ $key: $value<br>";
334                        #}
335                        #print "restored Session<br>";
336                }
337               
338                function saveProfile($_globalSettings, $_smtpSettings, $_imapSettings)
339                {
340                        if(!isset($_globalSettings['profileID']))
341                        {
342                                $this->soemailadmin->addProfile($_globalSettings, $_smtpSettings, $_imapSettings);
343                        }
344                        else
345                        {
346                                $this->soemailadmin->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings);
347                        }
348                }
349               
350                function saveSessionData()
351                {
352                        global $phpgw;
353                       
354                        $phpgw->session->appsession('session_data','',$this->sessionData);
355                        $phpgw->session->appsession('user_session_data','',$this->userSessionData);
356                }
357               
358                function saveUserData($_accountID, $_formData, $_boAction)
359                {
360                        $this->userSessionData[$_accountID]['mailLocalAddress']         = $_formData["mailLocalAddress"];
361                        $this->userSessionData[$_accountID]['accountStatus']            = $_formData["accountStatus"];
362                        $this->userSessionData[$_accountID]['deliveryMode']             = $_formData["deliveryMode"];
363                        $this->userSessionData[$_accountID]['qmailDotMode']             = $_formData["qmailDotMode"];
364                        $this->userSessionData[$_accountID]['deliveryProgramPath']      = $_formData["deliveryProgramPath"];
365                        $this->userSessionData[$_accountID]['quotaLimit']               = $_formData["quotaLimit"];
366
367                        switch ($_boAction)
368                        {
369                                case 'add_mailAlternateAddress':
370                                        if (is_array($this->userSessionData[$_accountID]['mailAlternateAddress']))
371                                        {
372                                                $count = count($this->userSessionData[$_accountID]['mailAlternateAddress']);
373                                        }
374                                        else
375                                        {
376                                                $count = 0;
377                                                $this->userSessionData[$_accountID]['mailAlternateAddress'] = array();
378                                        }
379                                       
380                                        $this->userSessionData[$_accountID]['mailAlternateAddress'][$count] =
381                                                $_formData['add_mailAlternateAddress'];
382                                               
383                                        $this->saveSessionData();
384                                       
385                                        break;
386                                       
387                                case 'remove_mailAlternateAddress':
388                                        $i=0;
389                                       
390                                        while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailAlternateAddress']))
391                                        {
392                                                #print ".. $key: $value<br>";
393                                                if ($key != $_formData['remove_mailAlternateAddress'])
394                                                {
395                                                        $newMailAlternateAddress[$i]=$value;
396                                                        #print "!! $i: $value<br>";
397                                                        $i++;
398                                                }
399                                        }
400                                        $this->userSessionData[$_accountID]['mailAlternateAddress'] = $newMailAlternateAddress;
401                                       
402                                        $this->saveSessionData();
403
404                                        break;
405                                       
406                                case 'add_mailRoutingAddress':
407                                        if (is_array($this->userSessionData[$_accountID]['mailRoutingAddress']))
408                                        {
409                                                $count = count($this->userSessionData[$_accountID]['mailRoutingAddress']);
410                                        }
411                                        else
412                                        {
413                                                $count = 0;
414                                                $this->userSessionData[$_accountID]['mailRoutingAddress'] = array();
415                                        }
416                                       
417                                        $this->userSessionData[$_accountID]['mailRoutingAddress'][$count] =
418                                                $_formData['add_mailRoutingAddress'];
419                                               
420                                        $this->saveSessionData();
421
422                                        break;
423                                       
424                                case 'remove_mailRoutingAddress':
425                                        $i=0;
426                                       
427                                        while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailRoutingAddress']))
428                                        {
429                                                if ($key != $_formData['remove_mailRoutingAddress'])
430                                                {
431                                                        $newMailRoutingAddress[$i]=$value;
432                                                        $i++;
433                                                }
434                                        }
435                                        $this->userSessionData[$_accountID]['mailRoutingAddress'] = $newMailRoutingAddress;
436                                       
437                                        $this->saveSessionData();
438
439                                        break;
440                                       
441                                case 'save':
442                                        $this->soemailadmin->saveUserData(
443                                                $_accountID,
444                                                $this->userSessionData[$_accountID]);
445                                        $bofelamimail = CreateObject('felamimail.bofelamimail');
446                                        $bofelamimail->openConnection('','',true);
447                                        $bofelamimail->imapSetQuota($GLOBALS['phpgw']->accounts->id2name($_accountID),
448                                                                    $this->userSessionData[$_accountID]['quotaLimit']);
449                                        $bofelamimail->closeConnection();
450                                        $GLOBALS['phpgw']->accounts->cache_invalidate($_accountID);
451                                       
452                                       
453                                        break;
454                        }
455                }
456
457                function updateAccount($_hookValues)
458                {
459                        if (!empty($this->imapClass))
460                        {
461                                ExecMethod("emailadmin.".$this->imapClass.".updateAccount",$_hookValues,3,$this->profileData);
462                        }
463
464                        if (!empty($this->smtpClass))
465                        {
466                                ExecMethod("emailadmin.".$this->smtpClass.".updateAccount",$_hookValues,3,$this->profileData);
467                        }
468                }
469               
470        }
471?>
Note: See TracBrowser for help on using the repository browser.