squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

setup.php
Go to the documentation of this file.
1 <?php
2 
19 define('SMPREF_SENT_SUBFOLDERS_DISABLED', 0);
20 define('SMPREF_SENT_SUBFOLDERS_YEARLY', 1);
21 define('SMPREF_SENT_SUBFOLDERS_QUARTERLY', 2);
22 define('SMPREF_SENT_SUBFOLDERS_MONTHLY', 3);
23 define('SMOPT_GRP_SENT_SUBFOLDERS','SENT_SUBFOLDERS');
24 
29  /* Standard initialization API. */
31 
32  /* The hooks to make the sent subfolders display correctly. */
34  ['check_handleAsSent_result']['sent_subfolders'] =
35  'sent_subfolders_check_handleAsSent';
36 
37  /* The hooks to automatically update sent subfolders. */
39  ['left_main_before']['sent_subfolders'] =
40  'sent_subfolders_update_sentfolder';
41 
43  ['compose_send']['sent_subfolders'] =
44  'sent_subfolders_update_sentfolder';
45 
46  /* The hook to load the sent subfolders prefs. */
48  ['loading_prefs']['sent_subfolders'] =
49  'sent_subfolders_load_prefs';
50 
51  /* The hooks to handle sent subfolders options. */
53  ['optpage_loadhook_folder']['sent_subfolders'] =
54  'sent_subfolders_optpage_loadhook_folders';
55 
56  /* mark base sent folder as special mailbox */
58  ['special_mailbox']['sent_subfolders'] =
59  'sent_subfolders_special_mailbox';
60 }
61 
63  global $handleAsSent_result, $sent_subfolders_base,
64  $use_sent_subfolders;
65 
66  $args = func_get_arg(0);
67  sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
68 
69  /* Only check the folder string if we have been passed a mailbox. */
70  if ($use_sent_subfolders && (count($args) > 1)) {
71  /* Chop up the folder strings as needed. */
72  $base_str = $sent_subfolders_base . $delimiter;
73  $mbox_str = substr($args[1], 0, strlen($base_str));
74 
75  /* Perform the comparison. */
76  $handleAsSent_result =
77  ( $handleAsSent_result
78  || ($base_str == $mbox_str)
79  || ($sent_subfolders_base == $args[1])
80  );
81  }
82 }
83 
88  global $use_sent_subfolders, $data_dir, $username, $sent_folder,
89  $sent_subfolders_setting, $sent_subfolders_base;
90 
91  $use_sent_subfolders = getPref
92  ($data_dir, $username, 'use_sent_subfolders', SMPREF_OFF);
93 
94  $sent_subfolders_setting = getPref
95  ($data_dir, $username, 'sent_subfolders_setting', SMPREF_SENT_SUBFOLDERS_DISABLED);
96 
97  $sent_subfolders_base = getPref
98  ($data_dir, $username, 'sent_subfolders_base', $sent_folder);
99 }
100 
105  global $optpage_data, $imapServerAddress, $imapPort;
106 
107  sqgetGlobalVar('username', $username, SQ_SESSION);
108  sqgetGlobalVar('key', $key, SQ_COOKIE);
109 
110  /* Get some imap data we need later. */
115 
116  /* Load the Sent Subfolder Options into an array. */
117  $optgrp = _("Sent Subfolders Options");
118  $optvals = array();
119 
120  $optvals[] = array(
121  'name' => 'sent_subfolders_setting',
122  'caption' => _("Use Sent Subfolders"),
123  'type' => SMOPT_TYPE_STRLIST,
124  'refresh' => SMOPT_REFRESH_FOLDERLIST,
125  'posvals' => array(SMPREF_SENT_SUBFOLDERS_DISABLED => _("Disabled"),
126  SMPREF_SENT_SUBFOLDERS_MONTHLY => _("Monthly"),
127  SMPREF_SENT_SUBFOLDERS_QUARTERLY => _("Quarterly"),
128  SMPREF_SENT_SUBFOLDERS_YEARLY => _("Yearly")),
129  'save' => 'save_option_sent_subfolders_setting'
130  );
131 
132  $filtered_folders=array_filter($boxes, "filter_folders");
133  $sent_subfolders_base_values = array('whatever'=>$filtered_folders);
134 
135  $optvals[] = array(
136  'name' => 'sent_subfolders_base',
137  'caption' => _("Base Sent Folder"),
138  'type' => SMOPT_TYPE_FLDRLIST,
139  'refresh' => SMOPT_REFRESH_FOLDERLIST,
140  'posvals' => $sent_subfolders_base_values,
141  'save' => 'save_option_sent_subfolders_base',
142  );
143 
144  /* Add our option data to the global array. */
145  $optpage_data['grps'][SMOPT_GRP_SENT_SUBFOLDERS] = $optgrp;
146  $optpage_data['vals'][SMOPT_GRP_SENT_SUBFOLDERS] = $optvals;
147 }
148 
157 function filter_folders($fldr) {
158  return strtolower($fldr['unformatted'])!='inbox';
159 }
160 
165  global $data_dir, $username, $use_sent_subfolders, $sent_subfolders_base;
166 
167  /* Set use_sent_subfolders as either on or off. */
168  if ($option->new_value == SMPREF_SENT_SUBFOLDERS_DISABLED) {
169  setPref($data_dir, $username, 'use_sent_subfolders', SMPREF_OFF);
170  // for lack of anything better
171  setPref($data_dir, $username, 'sent_folder', $sent_subfolders_base);
172  } else {
173  setPref($data_dir, $username, 'use_sent_subfolders', SMPREF_ON);
174  setPref($data_dir, $username, 'move_to_sent', SMPREF_ON);
175  }
176 
177  /* Now just save the option as normal. */
178  save_option($option);
179 }
180 
188  global $sent_folder, $auto_create_special, $auto_create_done;
189  global $sent_subfolders_base, $sent_subfolders_setting;
191  global $use_sent_subfolders, $move_to_sent, $imap_server_type;
192 
193  sqgetGlobalVar('username', $username, SQ_SESSION);
194  sqgetGlobalVar('key', $key, SQ_COOKIE);
195  sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
196 
197  if ($use_sent_subfolders || $move_to_sent) {
198  $year = date('Y');
199  $month = date('m');
200  $quarter = sent_subfolder_getQuarter($month);
201 
202  /*
203  Regarding the structure we've got three main possibilities.
204  One sent holder. level 0.
205  Multiple year holders with messages in it. level 1.
206  Multiple year folders with holders in it. level 2.
207  */
208 /*
209  if( $imap_server_type == 'uw' ) {
210  $cnd_delimiter = '';
211  } else {
212  $cnd_delimiter = $delimiter;
213  }
214 */
215  $cnd_delimiter = $delimiter;
216 
217  switch ($sent_subfolders_setting) {
219  $level = 1;
220  $sent_subfolder = $sent_subfolders_base . $cnd_delimiter
221  . $year;
222  break;
224  $level = 2;
225  $sent_subfolder = $sent_subfolders_base . $cnd_delimiter
226  . $year
227  . $delimiter . $quarter;
228  $year_folder = $sent_subfolders_base . $cnd_delimiter
229  . $year;
230  break;
232  $level = 2;
233  $sent_subfolder = $sent_subfolders_base . $cnd_delimiter
234  . $year
235  . $delimiter . $month;
236  $year_folder = $sent_subfolders_base . $cnd_delimiter . $year;
237  break;
239  default:
240  $level = 0;
241  $sent_subfolder = $sent_folder;
242  $year_folder = $sent_folder;
243  }
244 
245  /* If this folder is NOT the current sent folder, update stuff. */
246  if ($sent_subfolder != $sent_folder) {
247  /* First, update the sent folder. */
248 
249  setPref($data_dir, $username, 'sent_folder', $sent_subfolder);
250  setPref($data_dir, $username, 'move_to_sent', SMPREF_ON);
251  $sent_folder = $sent_subfolder;
252  $move_to_sent = SMPREF_ON;
253 
254  /* Auto-create folders, if they do not yet exist. */
255  if ($sent_folder != 'none') {
256  /* Create the imap connection. */
257  $ic = sqimap_login
258  ($username, $key, $imapServerAddress, $imapPort, 10);
259 
260  /* Auto-create the year folder, if it does not yet exist.
261  (only for monthly/quarterly modes */
262  if ($sent_subfolders_setting != SMPREF_SENT_SUBFOLDERS_YEARLY) {
263  if (!sqimap_mailbox_exists($ic, $year_folder)) {
264  sqimap_mailbox_create($ic, $year_folder, ($level==1)?'':'noselect');
265  } else if (!sqimap_mailbox_is_subscribed($ic, $year_folder)) {
266  sqimap_subscribe($ic, $year_folder);
267  }
268  }
269 
270  /* Auto-create the subfolder, if it does not yet exist. */
271  if (!sqimap_mailbox_exists($ic, $sent_folder)) {
273  } else if (!sqimap_mailbox_is_subscribed($ic, $sent_subfolder)) {
274  sqimap_subscribe($ic, $sent_subfolder);
275  }
276 
277  /* Close the imap connection. */
278  sqimap_logout($ic);
279  }
280  }
281  }
282 }
283 
288  // first save the option as normal
289  save_option($option);
290 
291  // now update folder settings and auto-create first subfolder if needed
293 }
294 
301 function sent_subfolder_getQuarter($month) {
302  switch ($month) {
303  case '01':
304  case '02':
305  case '03':
306  $result = '1';
307  break;
308  case '04':
309  case '05':
310  case '06':
311  $result = '2';
312  break;
313  case '07':
314  case '08':
315  case '09':
316  $result = '3';
317  break;
318  case '10':
319  case '11':
320  case '12':
321  $result = '4';
322  break;
323  default:
324  $result = 'ERR';
325  }
326 
327  /* Return the current quarter. */
328  return ('Q' . $result);
329 }
330 
339 
340  sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
341 /*
342  if( $imap_server_type == 'uw' ) {
343  $cnd_delimiter = '';
344  } else {
345  $cnd_delimiter = $delimiter;
346  }
347 */
348  $cnd_delimiter = $delimiter;
349 
350  $use_sent_subfolders = getPref
351  ($data_dir, $username, 'use_sent_subfolders', SMPREF_OFF);
352  $sent_subfolders_base = getPref($data_dir, $username, 'sent_subfolders_base', $sent_folder);
353 
354  if ($use_sent_subfolders == SMPREF_ON &&
355  ($mb == $sent_subfolders_base || stristr($mb,$sent_subfolders_base. $cnd_delimiter) ) ) {
356  return 1;
357  }
358  return 0;
359 }
sent_subfolders_update_sentfolder
sent_subfolders_update_sentfolder()
Definition: setup.php:187
SMPREF_SENT_SUBFOLDERS_MONTHLY
const SMPREF_SENT_SUBFOLDERS_MONTHLY
Definition: setup.php:22
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$imapConnection
$imapConnection
Definition: message_details_bottom.php:74
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
SMPREF_SENT_SUBFOLDERS_YEARLY
const SMPREF_SENT_SUBFOLDERS_YEARLY
Definition: setup.php:20
$imapServerAddress
$imapServerAddress
Definition: config_default.php:202
sqimap_login
sqimap_login($username, $password, $imap_server_address, $imap_port, $hide)
Definition: imap_general.php:481
SMOPT_GRP_SENT_SUBFOLDERS
const SMOPT_GRP_SENT_SUBFOLDERS
Definition: setup.php:23
$data_dir
$data_dir
Definition: config_default.php:499
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
$imap_server_type
$imap_server_type
Definition: config_default.php:231
sqimap_mailbox_exists
sqimap_mailbox_exists($imap_stream, $mailbox)
Definition: imap_mailbox.php:226
setPref
setPref($data_dir, $username, $string, $set_to)
Definition: db_prefs.php:352
SMOPT_REFRESH_FOLDERLIST
const SMOPT_REFRESH_FOLDERLIST
Definition: options.php:45
sent_subfolders_check_handleAsSent
sent_subfolders_check_handleAsSent()
Definition: setup.php:62
$username
global $username
Definition: validate.php:55
sqimap_mailbox_create
sqimap_mailbox_create($imap_stream, $mailbox, $type)
Definition: imap_mailbox.php:296
$auto_create_special
$auto_create_special
Definition: config_default.php:416
sent_subfolders_optpage_loadhook_folders
sent_subfolders_optpage_loadhook_folders()
Definition: setup.php:104
$boxes
$boxes
Definition: empty_trash.php:49
$sent_folder
$sent_folder
Definition: config_default.php:395
$squirrelmail_plugin_hooks
global $squirrelmail_plugin_hooks
Definition: plugin.php:17
sqimap_logout
sqimap_logout($imap_stream)
Definition: imap_general.php:639
SMPREF_SENT_SUBFOLDERS_QUARTERLY
const SMPREF_SENT_SUBFOLDERS_QUARTERLY
Definition: setup.php:21
SMPREF_OFF
const SMPREF_OFF
Definition: constants.php:26
save_option_sent_subfolders_setting
save_option_sent_subfolders_setting($option)
Definition: setup.php:164
sqimap_subscribe
sqimap_subscribe($imap_stream, $mailbox)
Definition: imap_mailbox.php:312
_
_($str)
Definition: gettext.php:160
save_option_sent_subfolders_base
save_option_sent_subfolders_base($option)
Definition: setup.php:287
SMOPT_TYPE_STRLIST
const SMOPT_TYPE_STRLIST
Definition: options.php:21
sqimap_mailbox_is_subscribed
sqimap_mailbox_is_subscribed($imap_stream, $folder)
Definition: imap_mailbox.php:348
$imapPort
$imapPort
Definition: config_default.php:210
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19
squirrelmail_plugin_init_sent_subfolders
squirrelmail_plugin_init_sent_subfolders()
Definition: setup.php:28
save_option
save_option($option)
Definition: options.php:847
sent_subfolders_special_mailbox
sent_subfolders_special_mailbox($mb)
Definition: setup.php:337
sent_subfolders_load_prefs
sent_subfolders_load_prefs()
Definition: setup.php:87
SMOPT_TYPE_FLDRLIST
const SMOPT_TYPE_FLDRLIST
Definition: options.php:28
SMPREF_ON
const SMPREF_ON
Definition: constants.php:28
sent_subfolder_getQuarter
sent_subfolder_getQuarter($month)
Definition: setup.php:301
SMPREF_SENT_SUBFOLDERS_DISABLED
const SMPREF_SENT_SUBFOLDERS_DISABLED
Definition: setup.php:19
sqimap_mailbox_list
sqimap_mailbox_list($imap_stream, $force=false)
Definition: imap_mailbox.php:597
filter_folders
filter_folders($fldr)
Definition: setup.php:157