~ubuntu-branches/ubuntu/vivid/gosa/vivid

« back to all changes in this revision

Viewing changes to kolab/personal/mail/kolab/class_mail-methods-kolab.inc

Tags: 2.7.1-1
* New upstream release
* Updated packaging to not include smarty (Closes: #620489)
* Fixed case of POSIX (Closes: #620486)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
 
 
4
class mailMethodKolab extends mailMethodCyrus
 
5
{
 
6
  /* Allow modification of account_ids for existing mail accounts */
 
7
  protected $modifyableMail   = FALSE;
 
8
 
 
9
  /* Allow modification of the mail server attribute existing mail accounts */
 
10
  protected $modifyableServer = TRUE;
 
11
 
 
12
  /* Enforces same value for 'mail' as used for 'cn' */
 
13
  protected $mailEqualsCN   = TRUE; 
 
14
 
 
15
  /* Enabled mail domain selection. If enabled getMailDomains must the domain parts */ 
 
16
  protected $enableDomainSelection= FALSE;
 
17
  protected $enableQuota          = TRUE;
 
18
  protected $enableSieveManager   = TRUE;
 
19
  protected $enableVacationRange  = TRUE;
 
20
  protected $enableFolderTypes    = TRUE;
 
21
 
 
22
  protected $attributes           = array(
 
23
      "kolabDeleteflag" => "kolabDeleteflag",
 
24
      "kolabFolderType" => "kolabFolderType",
 
25
      "alias" => "gosaMailAlternateAddress",
 
26
      "cyrus-userquota" => "gosaMailQuota",
 
27
      "kolabHomeServer" => "gosaMailServer");
 
28
 
 
29
  protected $user_prefix    = 'user.';
 
30
  protected $share_prefix   = 'shared\\.';
 
31
 
 
32
  /* gosaSharedFolderTarget settings, 
 
33
   *   E.g. 
 
34
   *     AccountID = 'shared/herberts.folder@gonicus.de' 
 
35
   *     'kolab+' will result in gosaSharedFolderTarget: kolab+shared/herberts.folder@gonicus.de
 
36
   *
 
37
   * May be overridden in the gosa.conf.
 
38
   */
 
39
  protected $gosaSharedPrefix = 'kolab+';  
 
40
 
 
41
  /* Account ID creation */
 
42
  protected $user_id    = "%prefix%%uattrib%";  
 
43
  protected $share_id   = "%prefix%%cn%@%domain%";
 
44
 
 
45
  protected $userObjectClasses = array("kolabInetOrgPerson");
 
46
  protected $shareObjectClasses = array("kolabSharedFolder");
 
47
 
 
48
  /* Handle account removal like a master/slave kolab setup.
 
49
   * The kolabDeleteflag will be added for each server.
 
50
   */
 
51
  protected $masterSlave = TRUE;
 
52
 
 
53
  protected $acl_map = array(
 
54
      "lrsw"     => "read",
 
55
      "lrswp"    => "post",
 
56
      "p"        => "external post",
 
57
      "lrswip"   => "append",
 
58
      "lrswipcd" => "write",
 
59
      "lrswipcda"=> "admin",
 
60
      "lrswipkxtecda"=> "full-admin",
 
61
      " "         => "none"); 
 
62
  public function fixAttributesOnLoad()
 
63
  {
 
64
    mailMethodCyrus::fixAttributesOnLoad();
 
65
 
 
66
    // Tell our parent that there is a relatioship between alias and
 
67
    //  gosaMailAlternateAddress.  (Avoid plugin::cleanup to filter out alias).
 
68
    if(isset($this->parent->saved_attributes['gosaMailAlternateAddress'])){
 
69
      $this->parent->saved_attributes['alias'] = $this->parent->saved_attributes['gosaMailAlternateAddress'];
 
70
    }
 
71
  }
 
72
 
 
73
  public function fixAttributesOnStore()
 
74
  {
 
75
    mailMethod::fixAttributesOnStore();
 
76
    $this->build_account_id();
 
77
    $this->parent->attrs['kolabDeleteflag'] = array();
 
78
 
 
79
    /* The folderType is set by ::setFolderType(...) */
 
80
    $this->parent->attrs['kolabFolderType'] = array();
 
81
    if($this->type == "group"){ 
 
82
      $this->parent->attrs['gosaSharedFolderTarget'] = 
 
83
        $this->gosaSharedPrefix.$this->account_id;
 
84
    }
 
85
  }
 
86
 
 
87
  public function fixAttributesOnRemove()
 
88
  {
 
89
    mailMethod::fixAttributesOnRemove();
 
90
    foreach($this->attributes as $source => $dest){
 
91
      $this->attrs[$dest]   = array();
 
92
      $this->attrs[$source] = array();
 
93
    }
 
94
    if($this->type == "user"){
 
95
      $ocs = $this->userObjectClasses;
 
96
    }else{
 
97
      $ocs = $this->shareObjectClasses;
 
98
    }
 
99
    $this->parent->attrs['objectClass'] = array_merge( $this->parent->attrs['objectClass'],$ocs);
 
100
    $this->parent->attrs['objectClass'] = array_unique($this->parent->attrs['objectClass']);
 
101
 
 
102
    if($this->type == "group"){ 
 
103
      $this->parent->attrs['gosaSharedFolderTarget'] =array();
 
104
    }
 
105
 
 
106
    /* If the mail setup includes Master and Slave Kolab Server, then we have to remove the 
 
107
     *  mailAccount from server, by adding a kolabDeleteflag for each server.
 
108
     * */
 
109
    if($this->masterSlave){
 
110
      $this->parent->attrs['kolabDeleteflag'] = array();
 
111
      foreach($this->getKolabHost() as $md){
 
112
        $this->parent->attrs['kolabDeleteflag'][] = $md;
 
113
      }
 
114
    }else{
 
115
      $this->parent->attrs['kolabDeleteflag'] = $this->parent->gosaMailServer;
 
116
    }
 
117
    if($this->folderTypesEnabled()){
 
118
      $this->parent->attrs['kolabFolderType'] =array();
 
119
    }
 
120
  }
 
121
 
 
122
 
 
123
  /* \brief   Some method require special folder types, "kolab" for example.
 
124
      !! Those values are dummy values, the base class doesn't use folder types;
 
125
     @return  Array Return folder types.
 
126
   */
 
127
  public function getAvailableFolderTypes()
 
128
  {
 
129
    $ret = array();
 
130
    $ret['CAT'][''] = _("Unspecified"); 
 
131
    $ret['CAT']['mail']= _("Mails"); 
 
132
    $ret['CAT']['task']= _("Tasks"); 
 
133
    $ret['CAT']['journal']= _("Journals"); 
 
134
    $ret['CAT']['event']= _("Calendar"); 
 
135
    $ret['CAT']['contact']= _("Contacts"); 
 
136
    $ret['CAT']['note']= _("Notes"); 
 
137
 
 
138
    $ret['SUB_CAT']['']['']     = _("Unspecified"); 
 
139
    $ret['SUB_CAT']['mail'][''] = _("Unspecified"); 
 
140
    $ret['SUB_CAT']['mail']['inbox']      = _("Inbox"); 
 
141
    $ret['SUB_CAT']['mail']['drafts']     = _("Drafts"); 
 
142
    $ret['SUB_CAT']['mail']['sentitems']  = _("Sent"); 
 
143
    $ret['SUB_CAT']['mail']['junkemail']  = _("SPAM"); 
 
144
 
 
145
    $ret['SUB_CAT']['task']['default']     = _("Default"); 
 
146
    $ret['SUB_CAT']['journal']['default']  = _("Default"); 
 
147
    $ret['SUB_CAT']['event']['default']    = _("Default"); 
 
148
    $ret['SUB_CAT']['contact']['default']  = _("Default"); 
 
149
    $ret['SUB_CAT']['note']['default']     = _("Default"); 
 
150
 
 
151
    return($ret);
 
152
  }
 
153
 
 
154
 
 
155
  /*! \brief  Checks whether this account is removeable or not.
 
156
              There may be some dependencies left, eg. kolab.
 
157
   */
 
158
  public function accountRemoveable(&$reason = "")
 
159
  {
 
160
    if(isset($this->parent->attrs)){
 
161
      $checkArray  = array("kolabInvitationPolicy","unrestrictedMailSize", "calFBURL","kolabDelegate","kolabFreeBusyFuture");
 
162
      foreach($checkArray as $index){
 
163
        if(isset($this->parent->attrs[$index])){
 
164
          $reason = _("Mail settings cannot be removed while there are delegations configured!");
 
165
          return(false);
 
166
        }
 
167
      }
 
168
    }
 
169
    return(true);
 
170
  }
 
171
 
 
172
 
 
173
 
 
174
  /* \brief  Returns the selected folder type. 
 
175
      !! Those values are dummy values, the base class doesn't use folder types;
 
176
     @return  Array  The folde type.
 
177
   */
 
178
  public function getFolderType($default)
 
179
  {
 
180
    if($this->enableFolderTypes && isset($this->parent->attrs['kolabFolderType'][0])){
 
181
      $type = $this->parent->attrs['kolabFolderType'][0];
 
182
      if(strpos($type,".")){
 
183
        list($cat,$sub) = explode(".",$this->parent->attrs['kolabFolderType'][0]);
 
184
      }else{
 
185
        $sub = "";
 
186
        $cat = $type;
 
187
      }
 
188
 
 
189
      return(array("CAT" => $cat, "SUB_CAT" => $sub));
 
190
    }else{
 
191
      return($default);
 
192
    }
 
193
  }
 
194
 
 
195
 
 
196
  /* \brief  Returns the selected folder type. 
 
197
      !! Those values are dummy values, the base class doesn't use folder types;
 
198
     @return  Array  The folde type.
 
199
   */
 
200
  public function setFolderType($type)
 
201
  {
 
202
 
 
203
    $type_str = trim($type['CAT'].".".$type['SUB_CAT']);
 
204
    $type_str = trim($type_str,".");
 
205
    $attrs = array();
 
206
    if(empty($type_str)){
 
207
      $attrs['kolabFolderType'] = array();
 
208
    }else{
 
209
      $attrs['kolabFolderType'] = $type_str;
 
210
    }
 
211
 
 
212
    $ldap = $this->config->get_ldap_link();
 
213
    $ldap->cd ($this->parent->dn);
 
214
    $ldap->modify($attrs);
 
215
    if($ldap->success()){
 
216
      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>Successful</b>", 
 
217
          "<b>MAIL:</b> Set folderType to '".$type_str."'");
 
218
    }else{
 
219
      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>Failed: </b>".$ldap->get_error(), 
 
220
          "<b>MAIL:</b> Set folderType to '".$type_str."'");
 
221
    }
 
222
  }
 
223
 
 
224
 
 
225
  public function setQuota($number)
 
226
  {
 
227
    mailMethod::setQuota($number);
 
228
    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>Skipped, part of kolabd!</b>", 
 
229
        "<b>Set account quota</b> on server '".$this->MailServer);
 
230
    return(TRUE);
 
231
  }
 
232
 
 
233
  public function  setFolderACLs($permissions)
 
234
  {
 
235
    mailMethod::setFolderACLs($permissions);
 
236
    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>Skipped, part of kolabd!</b>", 
 
237
        "<b>Setting folder ACLs!</b>","");
 
238
    return(TRUE);
 
239
  }
 
240
 
 
241
  public function updateMailbox()
 
242
  {
 
243
    mailMethod::updateMailbox();
 
244
    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>Skipped, part of kolabd!</b>", 
 
245
        "<b>Add/Update account</b> on server :".$this->MailServer);
 
246
    return(TRUE);
 
247
  }
 
248
 
 
249
  public function deleteMailbox()
 
250
  {
 
251
    mailMethod::deleteMailbox();
 
252
    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "Skipped, part of kolabd!", 
 
253
      "<b>Setting Quota</b>");
 
254
    return(TRUE);
 
255
  }
 
256
 
 
257
 
 
258
  public function allow_remove(&$reason)
 
259
  {
 
260
    if(isset($this->parent->attrs)){
 
261
      if(in_array_ics("kolabDeleteflag",array_keys($this->parent->attrs))){
 
262
        $reason = _("Waiting for Kolab to remove mail properties...");
 
263
        return(FALSE);
 
264
      }elseif(in_array("gosaMailAccount",$this->parent->attrs['objectClass'])){
 
265
        $reason = _("Please remove the mail settings first!");
 
266
        return(FALSE);
 
267
      }
 
268
    }
 
269
    return(TRUE);
 
270
  }
 
271
 
 
272
 
 
273
 
 
274
  /*! \brief   Returns all kolabHost entries from the k=kolab object.
 
275
      @return  See \brief
 
276
   */
 
277
  public function getKolabHost()
 
278
  {
 
279
    $host = array();
 
280
    $ldap = $this->config->get_ldap_link();
 
281
    $ldap->cd($this->config->current['BASE']);
 
282
    $ldap->search("(&(objectClass=kolab)(k=kolab)(kolabHost=*))",array("kolabHost"));
 
283
 
 
284
    if($ldap->count() == 1){
 
285
      $attrs = $ldap->fetch();
 
286
      for($i=0; $i <$attrs['kolabHost']['count']; $i ++ ){
 
287
        $host[] = $attrs['kolabHost'][$i];
 
288
      }
 
289
      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>Found: ".trim(implode($host,", "),", ")."</b>",
 
290
          "Revceiving 'Mail hosts for kolab22'.");
 
291
    }elseif($ldap->count() == 0){
 
292
      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>No mailHost entries found. Check k=kolab and mailHost</b>",
 
293
          "Revceiving 'Mail hosts for kolab22'.");
 
294
    }else{
 
295
      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>Found more than one kolab configuration object. Giving up.</b>",
 
296
          "Revceiving 'Mail hosts for kolab22'.");
 
297
    }
 
298
 
 
299
    return($host);
 
300
  }
 
301
}
 
302
 
 
303
 
 
304
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 
305
?>