4 * setup.php -- Sent Subfolders Setup File
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This is a standard Squirrelmail-1.2 API for plugins.
14 define('SMPREF_SENT_SUBFOLDERS_DISABLED', 0);
15 define('SMPREF_SENT_SUBFOLDERS_YEARLY', 1);
16 define('SMPREF_SENT_SUBFOLDERS_QUARTERLY', 2);
17 define('SMPREF_SENT_SUBFOLDERS_MONTHLY', 3);
18 define('SMOPT_GRP_SENT_SUBFOLDERS','SENT_SUBFOLDERS');
20 function squirrelmail_plugin_init_sent_subfolders() {
21 /* Standard initialization API. */
22 global $squirrelmail_plugin_hooks;
24 /* The hooks to make the sent subfolders display correctly. */
25 $squirrelmail_plugin_hooks
26 ['check_handleAsSent_result']['sent_subfolders'] =
27 'sent_subfolders_check_handleAsSent';
29 /* The hooks to automatically update sent subfolders. */
30 $squirrelmail_plugin_hooks
31 ['left_main_before']['sent_subfolders'] =
32 'sent_subfolders_update_sentfolder';
34 $squirrelmail_plugin_hooks
35 ['compose_send']['sent_subfolders'] =
36 'sent_subfolders_update_sentfolder';
38 /* The hook to load the sent subfolders prefs. */
39 $squirrelmail_plugin_hooks
40 ['loading_prefs']['sent_subfolders'] =
41 'sent_subfolders_load_prefs';
43 /* The hooks to handle sent subfolders options. */
44 $squirrelmail_plugin_hooks
45 ['optpage_loadhook_folder']['sent_subfolders'] =
46 'sent_subfolders_optpage_loadhook_folders';
49 function sent_subfolders_check_handleAsSent() {
50 global $handleAsSent_result, $sent_subfolders_base,
53 $sent_subfolders_base = 'INBOX.Sent';
54 $args = func_get_arg(0);
55 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
57 /* Only check the folder string if we have been passed a mailbox. */
58 if ($use_sent_subfolders && (count($args) > 1)) {
59 /* Chop up the folder strings as needed. */
60 $base_str = $sent_subfolders_base . $delimiter;
61 $mbox_str = substr($args[1], 0, strlen($base_str));
63 /* Perform the comparison. */
64 $handleAsSent_result =
65 ( $handleAsSent_result
66 ||
($base_str == $mbox_str)
67 ||
($sent_subfolders_base == $args[1])
72 function sent_subfolders_load_prefs() {
73 global $use_sent_subfolders, $data_dir, $username,
74 $sent_subfolders_setting, $sent_subfolders_base;
76 $use_sent_subfolders = getPref
77 ($data_dir, $username, 'use_sent_subfolders', SMPREF_OFF
);
79 $sent_subfolders_setting = getPref
80 ($data_dir, $username, 'sent_subfolders_setting', SMPREF_SENT_SUBFOLDERS_DISABLED
);
82 $sent_subfolders_base = getPref
83 ($data_dir, $username, 'sent_subfolders_base', SMPREF_NONE
);
86 function sent_subfolders_optpage_loadhook_folders() {
87 global $optpage_data, $imapServerAddress, $imapPort;
89 sqgetGlobalVar('username', $username, SQ_SESSION
);
90 sqgetGlobalVar('key', $key, SQ_COOKIE
);
92 /* Get some imap data we need later. */
94 sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
95 $boxes = sqimap_mailbox_list($imapConnection);
96 sqimap_logout($imapConnection);
98 /* Load the Sent Subfolder Options into an array. */
99 $optgrp = _("Sent Subfolders Options");
103 'name' => 'sent_subfolders_setting',
104 'caption' => _("Use Sent Subfolders"),
105 'type' => SMOPT_TYPE_STRLIST
,
106 'refresh' => SMOPT_REFRESH_FOLDERLIST
,
107 'posvals' => array(SMPREF_SENT_SUBFOLDERS_DISABLED
=> _("Disabled"),
108 SMPREF_SENT_SUBFOLDERS_MONTHLY
=> _("Monthly"),
109 SMPREF_SENT_SUBFOLDERS_QUARTERLY
=> _("Quarterly"),
110 SMPREF_SENT_SUBFOLDERS_YEARLY
=> _("Yearly")),
111 'save' => 'save_option_sent_subfolders_setting'
114 $sent_subfolders_base_values = array();
115 foreach ($boxes as $folder) {
116 if (strtolower($folder['unformatted']) != 'inbox') {
117 $real_value = $folder['unformatted-dm'];
118 $disp_value = str_replace(' ', ' ', $folder['formatted']);
119 $sent_subfolders_base_values[$real_value] = $disp_value;
124 'name' => 'sent_subfolders_base',
125 'caption' => _("Base Sent Folder"),
126 'type' => SMOPT_TYPE_STRLIST
,
127 'refresh' => SMOPT_REFRESH_FOLDERLIST
,
128 'posvals' => $sent_subfolders_base_values
131 /* Add our option data to the global array. */
132 $optpage_data['grps'][SMOPT_GRP_SENT_SUBFOLDERS
] = $optgrp;
133 $optpage_data['vals'][SMOPT_GRP_SENT_SUBFOLDERS
] = $optvals;
136 function save_option_sent_subfolders_setting($option) {
137 global $data_dir, $username, $use_sent_subfolders;
139 /* Set use_sent_subfolders as either on or off. */
140 if ($option->new_value
== SMPREF_SENT_SUBFOLDERS_DISABLED
) {
141 setPref($data_dir, $username, 'use_sent_subfolders', SMPREF_OFF
);
143 setPref($data_dir, $username, 'use_sent_subfolders', SMPREF_ON
);
144 setPref($data_dir, $username, 'move_to_sent', SMPREF_ON
);
147 /* Now just save the option as normal. */
148 save_option($option);
151 function sent_subfolders_update_sentfolder() {
152 global $sent_folder, $auto_create_special, $auto_create_done;
153 global $sent_subfolders_base, $sent_subfolders_setting;
154 global $data_dir, $imapServerAddress, $imapPort;
155 global $use_sent_subfolders, $move_to_sent, $imap_server_type;
157 sqgetGlobalVar('username', $username, SQ_SESSION
);
158 sqgetGlobalVar('key', $key, SQ_COOKIE
);
159 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
161 if ($use_sent_subfolders ||
$move_to_sent) {
164 $quarter = sent_subfolder_getQuarter($month);
167 Regarding the structure we've got three main possibilities.
168 One sent holder. level 0.
169 Multiple year holders with messages in it. level 1.
170 Multiple year folders with holders in it. level 2.
173 if( $imap_server_type == 'uw' ) {
176 $cnd_delimiter = $delimiter;
179 $cnd_delimiter = $delimiter;
181 switch ($sent_subfolders_setting) {
182 case SMPREF_SENT_SUBFOLDERS_YEARLY
:
184 $sent_subfolder = $sent_subfolders_base . $cnd_delimiter
187 case SMPREF_SENT_SUBFOLDERS_QUARTERLY
:
189 $sent_subfolder = $sent_subfolders_base . $cnd_delimiter
191 . $delimiter . $quarter;
192 $year_folder = $sent_subfolders_base
195 case SMPREF_SENT_SUBFOLDERS_MONTHLY
:
197 $sent_subfolder = $sent_subfolders_base . $cnd_delimiter
199 . $delimiter . $month;
200 $year_folder = $sent_subfolders_base . $year;
202 case SMPREF_SENT_SUBFOLDERS_DISABLED
:
205 $sent_subfolder = $sent_folder;
206 $year_folder = $sent_folder;
209 /* If this folder is NOT the current sent folder, update stuff. */
210 if ($sent_subfolder != $sent_folder) {
211 /* First, update the sent folder. */
213 setPref($data_dir, $username, 'sent_folder', $sent_subfolder);
214 setPref($data_dir, $username, 'move_to_sent', SMPREF_ON
);
215 $sent_folder = $sent_subfolder;
216 $move_to_sent = SMPREF_ON
;
218 /* Auto-create folders, if they do not yet exist. */
219 if ($sent_folder != 'none') {
220 /* Create the imap connection. */
222 ($username, $key, $imapServerAddress, $imapPort, 10);
224 /* Auto-create the year folder, if it does not yet exist. */
225 if (!sqimap_mailbox_exists($ic, $year_folder)) {
226 sqimap_mailbox_create($ic, $year_folder, ($level==1)?
'':'noselect');
227 } else if (!sqimap_mailbox_is_subscribed($ic, $year_folder)) {
228 sqimap_subscribe($ic, $year_folder);
231 /* Auto-create the subfolder, if it does not yet exist. */
232 if (!sqimap_mailbox_exists($ic, $sent_folder)) {
233 sqimap_mailbox_create($ic, $sent_folder, '');
234 } else if (!sqimap_mailbox_is_subscribed($ic, $sent_subfolder)) {
235 sqimap_subscribe($ic, $sent_subfolder);
238 /* Close the imap connection. */
245 function sent_subfolder_getQuarter($month) {
271 /* Return the current quarter. */
272 return ('Q' . $result);