options.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. /**
  3. ** mail_fetch/options.php
  4. **
  5. ** Copyright (c) 1999-2002 The SquirrelMail Project Team
  6. ** Licensed under the GNU GPL. For full terms see the file COPYING.
  7. **
  8. ** Setup of the mailfetch plugin.
  9. **
  10. ** $Id$
  11. **/
  12. chdir('..');
  13. require_once('../src/validate.php');
  14. require_once('../functions/imap.php');
  15. require_once('../src/load_prefs.php');
  16. displayPageHeader( $color, 'None' );
  17. //if dosen't select any option
  18. if (!isset($mf_action))
  19. $mf_action = 'config';
  20. switch( $mf_action ) {
  21. case 'add':
  22. if ($mf_sn<1) $mf_sn=0;
  23. if (!isset($mf_server)) return;
  24. setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
  25. setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
  26. setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
  27. setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
  28. if( $mf_cypher <> 'on' ) SetPref($data_dir,$username,"mailfetch_cypher", 'on');
  29. setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
  30. setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
  31. setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
  32. setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
  33. $mf_sn++;
  34. setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
  35. $mf_action = 'config';
  36. break;
  37. case 'confirm_modify':
  38. //modify a server
  39. if (!isset($mf_server)) return;
  40. setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
  41. setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
  42. setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
  43. setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
  44. if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
  45. setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
  46. setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
  47. setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
  48. setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
  49. $mf_action = 'config';
  50. break;
  51. case 'confirm_delete':
  52. //delete a server
  53. $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
  54. if ($mf_sn+1==$mailfetch_server_number) {
  55. //is the last server, whe can only decrase $mailfetch_server_number
  56. $mailfetch_server_number--;
  57. setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
  58. } else {
  59. //if not the last, all the sequel server come up one step
  60. //then whe decrase $mailfetch_server_number
  61. $mailfetch_server_number--;
  62. for ($i=$mf_sn;$i<$mailfetch_server_number;$i++) {
  63. $tmp=$i+1;
  64. setPref($data_dir,$username,"mailfetch_server_$i", getPref($data_dir, $username, "mailfetch_server_$tmp"));
  65. setPref($data_dir,$username,"mailfetch_alias_$i", getPref($data_dir, $username, "mailfetch_alias_$tmp"));
  66. setPref($data_dir,$username,"mailfetch_user_$i", getPref($data_dir, $username, "mailfetch_user_$tmp"));
  67. setPref($data_dir,$username,"mailfetch_pass_$i",(isset($mf_pass)?encrypt( $mf_pass ) :""));
  68. // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
  69. setPref($data_dir,$username,"mailfetch_lmos_$i", getPref($data_dir, $username, "mailfetch_lmos_$tmp"));
  70. setPref($data_dir,$username,"mailfetch_login_$i", getPref($data_dir, $username, "mailfetch_login_$tmp"));
  71. setPref($data_dir,$username,"mailfetch_fref_$i", getPref($data_dir, $username, "mailfetch_fref_$tmp"));
  72. setPref($data_dir,$username,"mailfetch_subfolder_$i", getPref($data_dir, $username, "mailfetch_subfolder_$tmp"));
  73. }
  74. setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
  75. }
  76. $mf_action = 'config';
  77. break;
  78. }
  79. $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
  80. $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
  81. if ($mailfetch_server_number<1) {
  82. $mailfetch_server_number=0;
  83. }
  84. for ($i=0;$i<$mailfetch_server_number;$i++) {
  85. $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
  86. $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
  87. $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
  88. $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
  89. $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
  90. $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
  91. $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
  92. $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
  93. $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
  94. if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
  95. }
  96. echo '<BR><form method=post action="'.$PHP_SELF.'">' .
  97. html_tag( 'table',
  98. html_tag( 'tr',
  99. html_tag( 'td',
  100. '<b>' . _("Remote POP server settings") . '</b>',
  101. 'center', $color[0] )
  102. ),
  103. 'center', '', 'width="95%" cols="1"' ) .
  104. html_tag( 'table',
  105. html_tag( 'tr',
  106. html_tag( 'td',
  107. _("You should be aware that the encryption used to store your password is not perfectly secure. However, if you are using pop, there is inherently no encryption anyway. Additionally, the encryption that we do to save it on the server can be undone by a hacker reading the source to this file." ) ,
  108. 'left' )
  109. ) .
  110. html_tag( 'tr',
  111. html_tag( 'td',
  112. _("If you leave password empty, it will be required when you fetch mail.") ,
  113. 'left' )
  114. ) .
  115. html_tag( 'tr',
  116. html_tag( 'td',
  117. '<input type=checkbox name=mf_cypher ' .
  118. (($mailfetch_cypher=='on')?'checked >':'>') .
  119. _("Encrypt passwords (informative only)") ,
  120. 'right' )
  121. ) ,
  122. 'center', '', 'width="95%" cols="1"' );
  123. switch( $mf_action ) {
  124. case 'config':
  125. echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
  126. html_tag( 'tr',
  127. html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
  128. ) .
  129. html_tag( 'tr' ) .
  130. html_tag( 'td', '', 'center', $color[0] ) .
  131. "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
  132. '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
  133. html_tag( 'table' ) .
  134. html_tag( 'tr',
  135. html_tag( 'th', _("Server:"), 'right' ) .
  136. html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
  137. ) .
  138. html_tag( 'tr',
  139. html_tag( 'th', _("Alias:"), 'right' ) .
  140. html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
  141. ) .
  142. html_tag( 'tr',
  143. html_tag( 'th', _("Username:"), 'right' ) .
  144. html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
  145. ) .
  146. html_tag( 'tr',
  147. html_tag( 'th', _("Password:"), 'right' ) .
  148. html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
  149. ) .
  150. html_tag( 'tr' ) .
  151. html_tag( 'th', _("Store in Folder:"), 'right' ) .
  152. html_tag( 'td', '', 'left' );
  153. $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
  154. $boxes = sqimap_mailbox_list($imapConnection);
  155. echo '<select name="mf_subfolder">';
  156. $boxes = sqimap_mailbox_list($imapConnection);
  157. for ($i = 0; $i < count($boxes); $i++) {
  158. if (!in_array('noselect', $boxes[$i]['flags'])) {
  159. $box = $boxes[$i]['unformatted'];
  160. $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
  161. if ( strtolower( $box2 ) == 'inbox' ) {
  162. $box2 = _("INBOX");
  163. }
  164. echo "<option value=\"$box\">$box2</option>\n";
  165. }
  166. }
  167. echo '</select></td></tr>' .
  168. html_tag( 'tr',
  169. html_tag( 'th', '&nbsp;', 'right' ) .
  170. html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
  171. ) .
  172. html_tag( 'tr',
  173. html_tag( 'th', '&nbsp;', 'right' ) .
  174. html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
  175. ) .
  176. html_tag( 'tr',
  177. html_tag( 'th', '&nbsp;', 'right' ) .
  178. html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
  179. ) .
  180. html_tag( 'tr',
  181. html_tag( 'td',
  182. '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
  183. 'center', '', 'colspan="2"' )
  184. ) .
  185. '</table></form></td></tr></table>';
  186. // Modify Server
  187. echo '<font size=-5><BR></font>' .
  188. html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
  189. html_tag( 'tr',
  190. html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
  191. ) .
  192. html_tag( 'tr' ) .
  193. html_tag( 'td', '', 'center', $color[0] );
  194. if ($mailfetch_server_number>0) {
  195. echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
  196. echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
  197. for ($i=0;$i<$mailfetch_server_number;$i++) {
  198. echo "<option value=\"$i\">" .
  199. (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</option>>";
  200. }
  201. echo '</select>'.
  202. '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
  203. '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
  204. '</form>';
  205. } else {
  206. echo _("No-one server in use. Try to add.");
  207. }
  208. echo '</td></tr></table>';
  209. break;
  210. case _("Delete"): //erase confirmation about a server
  211. echo html_tag( 'table',
  212. html_tag( 'tr',
  213. html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
  214. ) ,
  215. 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
  216. '<br>' .
  217. html_tag( 'table',
  218. html_tag( 'tr',
  219. html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
  220. ) .
  221. html_tag( 'tr',
  222. html_tag( 'td',
  223. "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
  224. '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
  225. '<br>' . _("Selected Server:") . " <b>$mailfetch_server_[$mf_sn]</b><br>" .
  226. _("Confirm delete of selected server?") . '<br><br>' .
  227. '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
  228. '<br></form>' ,
  229. 'center', $color[9] )
  230. ) ,
  231. 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
  232. break; //modify a server
  233. case _("Modify"):
  234. echo html_tag( 'table',
  235. html_tag( 'tr',
  236. html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
  237. ) ,
  238. 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
  239. '<br>' .
  240. html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
  241. html_tag( 'tr',
  242. html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
  243. ) .
  244. html_tag( 'tr' ) .
  245. html_tag( 'td', '', 'center', $color[0] ) .
  246. "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
  247. '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
  248. html_tag( 'table' ) .
  249. html_tag( 'tr',
  250. html_tag( 'th', _("Server:"), 'right' ) .
  251. html_tag( 'td', '<input type="text" name="mf_server" value="' . $mailfetch_server_[$mf_sn] . '" size="40">', 'left' )
  252. ) .
  253. html_tag( 'tr',
  254. html_tag( 'th', _("Alias:"), 'right' ) .
  255. html_tag( 'td', '<input type="text" name="mf_alias" value="' . $mailfetch_alias_[$mf_sn] . '" size="40">', 'left' )
  256. ) .
  257. html_tag( 'tr',
  258. html_tag( 'th', _("Username:"), 'right' ) .
  259. html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
  260. ) .
  261. html_tag( 'tr',
  262. html_tag( 'th', _("Password:"), 'right' ) .
  263. html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
  264. ) .
  265. html_tag( 'tr' ) .
  266. html_tag( 'th', _("Store in Folder:"), 'right' ) .
  267. html_tag( 'td', '', 'left' );
  268. $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
  269. $boxes = sqimap_mailbox_list($imapConnection);
  270. echo '<select name="mf_subfolder">';
  271. $boxes = sqimap_mailbox_list($imapConnection);
  272. for ($i = 0; $i < count($boxes); $i++) {
  273. if (!in_array('noselect', $boxes[$i]['flags'])) {
  274. $box = $boxes[$i]['unformatted'];
  275. $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
  276. if ( strtolower( $box2 ) == 'inbox' ) {
  277. $box2 = _("INBOX");
  278. }
  279. echo '<option ' .
  280. (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?'selected':'') .
  281. " value=\"$box\">$box2</option>\n";
  282. }
  283. }
  284. echo '</select></td></tr>' .
  285. html_tag( 'tr',
  286. html_tag( 'th', '&nbsp;', 'right' ) .
  287. html_tag( 'td',
  288. '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
  289. '>' . _("Leave Mail on Server") ,
  290. 'left' )
  291. ) .
  292. html_tag( 'tr',
  293. html_tag( 'th', '&nbsp;', 'right' ) .
  294. html_tag( 'td',
  295. '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
  296. '>' . _("Check mail during login"),
  297. 'left' )
  298. ) .
  299. html_tag( 'tr',
  300. html_tag( 'th', '&nbsp;', 'right' ) .
  301. html_tag( 'td',
  302. '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
  303. '>' . _("Check mail during folder refresh") ,
  304. 'left' )
  305. ) .
  306. html_tag( 'tr',
  307. html_tag( 'td',
  308. '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
  309. 'center', '', 'colspan="2"' )
  310. ) .
  311. '</table></form></td></tr></table>';
  312. break;
  313. default: //unsupported action
  314. echo '</form>' .
  315. html_tag( 'table',
  316. html_tag( 'tr',
  317. html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
  318. ) ,
  319. 'center', '', 'width="95%" cols="1"' ) .
  320. '<br>' .
  321. html_tag( 'table',
  322. html_tag( 'tr',
  323. html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
  324. html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
  325. ) ,
  326. 'center', '', 'width="70%" cols="1"' );
  327. }
  328. ?>
  329. </body></html>