utf-8 is already converted by ja_JP extra functions.
[squirrelmail.git] / plugins / mail_fetch / setup.php
CommitLineData
d622d38a 1<?php
2
d3c89357 3 /**
4 ** mail_fetch/setup.php
5 **
76911253 6 ** Copyright (c) 1999-2003 The SquirrelMail Project Team
d3c89357 7 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 **
9 ** Setup of the mailfetch plugin.
10 **
11 ** $Id$
12 **/
13
aa7fb30c 14 require_once(SM_PATH . 'plugins/mail_fetch/functions.php' );
d622d38a 15
16 function squirrelmail_plugin_init_mail_fetch() {
17 global $squirrelmail_plugin_hooks;
d622d38a 18
d3c89357 19 $squirrelmail_plugin_hooks['menuline']['mail_fetch'] = 'mail_fetch_link';
20 $squirrelmail_plugin_hooks['loading_prefs']['mail_fetch'] = 'mail_fetch_load_pref';
21 $squirrelmail_plugin_hooks['login_verified']['mail_fetch'] = 'mail_fetch_setnew';
22 $squirrelmail_plugin_hooks['left_main_before']['mail_fetch'] = 'mail_fetch_login';
d622d38a 23 $squirrelmail_plugin_hooks['optpage_register_block']['mail_fetch'] = 'mailfetch_optpage_register_block';
24
25 }
26
27 function mail_fetch_link() {
28
29 displayInternalLink('plugins/mail_fetch/fetch.php', _("Fetch"), '');
30 echo '&nbsp;&nbsp;';
31
32 }
33
34 function mail_fetch_load_pref() {
35
86bb8549 36 global $data_dir;
d622d38a 37 global $mailfetch_server_number;
38 global $mailfetch_cypher;
39 global $mailfetch_server_,$mailfetch_alias_,$mailfetch_user_,$mailfetch_pass_;
40 global $mailfetch_lmos_, $mailfetch_uidl_, $mailfetch_login_, $mailfetch_fref_;
41 global $PHP_SELF;
3c66c567 42
43 sqgetGlobalVar('username', $username, SQ_SESSION);
d622d38a 44
d3c89357 45 if( stristr( $PHP_SELF, 'mail_fetch' ) ) {
46 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
47 $mailfetch_cypher = getPref($data_dir, $username, 'mailfetch_cypher', 'on' );
d622d38a 48 if ($mailfetch_server_number<1) $mailfetch_server_number=0;
49 for ($i=0;$i<$mailfetch_server_number;$i++) {
50 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
e42b0dd2 51 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
d622d38a 52 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
53 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
54 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
55 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
56 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
57 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
58 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
59 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
60 }
61 }
62 }
63
d622d38a 64 function mail_fetch_login() {
65
97ffe963 66 require_once (SM_PATH . 'include/validate.php');
67 require_once (SM_PATH . 'functions/imap.php');
68 require_once (SM_PATH . 'plugins/mail_fetch/class.POP3.php');
69 require_once (SM_PATH . 'plugins/mail_fetch/functions.php');
d622d38a 70
86bb8549 71 global $data_dir, $imapServerAddress, $imapPort;
3c66c567 72
73 sqgetGlobalVar('username', $username, SQ_SESSION);
74 sqgetGlobalVar('key', $key, SQ_COOKIE);
d622d38a 75
76 $mailfetch_newlog = getPref($data_dir, $username, 'mailfetch_newlog');
77
78 $outMsg = '';
79
d3c89357 80 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number');
d622d38a 81 if (!isset($mailfetch_server_number)) $mailfetch_server_number=0;
d3c89357 82 $mailfetch_cypher = getPref($data_dir, $username, 'mailfetch_cypher');
d622d38a 83 if ($mailfetch_server_number<1) $mailfetch_server_number=0;
84
85 for ($i_loop=0;$i_loop<$mailfetch_server_number;$i_loop++) {
86
87 $mailfetch_login_[$i_loop] = getPref($data_dir, $username, "mailfetch_login_$i_loop");
88 $mailfetch_fref_[$i_loop] = getPref($data_dir, $username, "mailfetch_fref_$i_loop");
89 $mailfetch_pass_[$i_loop] = getPref($data_dir, $username, "mailfetch_pass_$i_loop");
90 if( $mailfetch_cypher == 'on' )
91 $mailfetch_pass_[$i_loop] = decrypt( $mailfetch_pass_[$i_loop] );
92
93 if( $mailfetch_pass_[$i_loop] <> '' && // Empty passwords no allowed
94 ( ( $mailfetch_login_[$i_loop] == 'on' && $mailfetch_newlog == 'on' ) || $mailfetch_fref_[$i_loop] == 'on' ) ) {
95
96 $mailfetch_server_[$i_loop] = getPref($data_dir, $username, "mailfetch_server_$i_loop");
e42b0dd2 97 $mailfetch_port_[$i_loop] = getPref($data_dir, $username , "mailfetch_port_$i_loop");
d622d38a 98 $mailfetch_alias_[$i_loop] = getPref($data_dir, $username, "mailfetch_alias_$i_loop");
99 $mailfetch_user_[$i_loop] = getPref($data_dir, $username, "mailfetch_user_$i_loop");
100 $mailfetch_lmos_[$i_loop] = getPref($data_dir, $username, "mailfetch_lmos_$i_loop");
101 $mailfetch_uidl_[$i_loop] = getPref($data_dir, $username, "mailfetch_uidl_$i_loop");
102 $mailfetch_subfolder_[$i_loop] = getPref($data_dir, $username, "mailfetch_subfolder_$i_loop");
103
104 $mailfetch_server=$mailfetch_server_[$i_loop];
e42b0dd2 105 $mailfetch_port=$mailfetch_port_[$i_loop];
d622d38a 106 $mailfetch_user=$mailfetch_user_[$i_loop];
107 $mailfetch_alias=$mailfetch_alias_[$i_loop];
108 $mailfetch_pass=$mailfetch_pass_[$i_loop];
109 $mailfetch_lmos=$mailfetch_lmos_[$i_loop];
110 $mailfetch_login=$mailfetch_login_[$i_loop];
111 $mailfetch_uidl=$mailfetch_uidl_[$i_loop];
112 $mailfetch_subfolder=$mailfetch_subfolder_[$i_loop];
113
114 // $outMsg .= "$mailfetch_alias checked<br>";
115
116 // $outMsg .= "$mailfetch_alias_[$i_loop]<br>";
117
118 $pop3 = new POP3($mailfetch_server, 60);
119
e42b0dd2 120 if (!$pop3->connect($mailfetch_server,$mailfetch_port)) {
d622d38a 121 $outMsg .= _("Warning, ") . $pop3->ERROR;
122 continue;
123 }
124
125 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
126
127 $Count = $pop3->login($mailfetch_user, $mailfetch_pass);
128 if (($Count == false || $Count == -1) && $pop3->ERROR != '') {
129 $outMsg .= _("Login Failed:") . $pop3->ERROR;
130 continue;
131 }
132
133 // register_shutdown_function($pop3->quit());
134
135 $msglist = $pop3->uidl();
136
137 $i = 1;
138 for ($j = 1; $j < sizeof($msglist); $j++) {
139 if ($msglist["$j"] == $mailfetch_uidl) {
140 $i = $j+1;
141 break;
142 }
143 }
144
145 if ($Count < $i) {
146 $pop3->quit();
147 continue;
148 }
149 if ($Count == 0) {
150 $pop3->quit();
151 continue;
152 } else {
153 $newmsgcount = $Count - $i + 1;
154 }
155
156 // Faster to get them all at once
157 $mailfetch_uidl = $pop3->uidl();
158
159 if (! is_array($mailfetch_uidl) && $mailfetch_lmos == 'on')
160 $outMsg .= _("Server does not support UIDL.");
161
162 for (; $i <= $Count; $i++) {
163 set_time_limit(20); // 20 seconds per message max
164 $Message = "";
165 $MessArray = $pop3->get($i);
166
167 if ( (!$MessArray) or (gettype($MessArray) != "array")) {
168 $outMsg .= _("Warning, ") . $pop3->ERROR;
169 continue 2;
170 }
171
172 while (list($lineNum, $line) = each ($MessArray)) {
173 $Message .= $line;
174 }
175
176 if ($mailfetch_subfolder=="") {
177 fputs($imap_stream, "A3$i APPEND INBOX {" . (strlen($Message) - 1) . "}\r\n");
178 } else {
179 fputs($imap_stream, "A3$i APPEND $mailfetch_subfolder {" . (strlen($Message) - 1) . "}\r\n");
180 }
181 $Line = fgets($imap_stream, 1024);
182 if (substr($Line, 0, 1) == '+') {
183 fputs($imap_stream, $Message);
184 sqimap_read_data($imap_stream, "A3$i", false, $response, $message);
185
186 if ($mailfetch_lmos != 'on') {
187 $pop3->delete($i);
188 }
189 } else {
190 echo "$Line";
191 $outMsg .= _("Error Appending Message!");
192 }
193 }
194
195 $pop3->quit();
196 sqimap_logout($imap_stream);
197 if (is_array($mailfetch_uidl)) {
198 setPref($data_dir,$username,"mailfetch_uidl_$i_loop", array_pop($mailfetch_uidl));
199 }
200 }
201 }
202
3c66c567 203 if( trim( $outMsg ) <> '' ) {
204 echo '<br><font size="1">' . _("Mail Fetch Result:") . "<br>$outMsg</font>";
205 }
206 if( $mailfetch_newlog == 'on' ) {
207 setPref($data_dir, $username, 'mailfetch_newlog', 'off');
208 }
d622d38a 209 }
210
211 function mail_fetch_setnew() {
212
86bb8549 213 global $data_dir;
aa7fb30c 214 require_once(SM_PATH . 'functions/prefs.php');
d622d38a 215
3c66c567 216 sqgetGlobalVar('username', $username, SQ_SESSION);
d622d38a 217
3c66c567 218 setPref( $data_dir, $username, 'mailfetch_newlog', 'on' );
d622d38a 219 }
220
221 function mailfetch_optpage_register_block() {
222 global $optpage_blocks;
223
224 $optpage_blocks[] = array(
225 'name' => _("Simple POP3 Fetch Mail"),
226 'url' => '../plugins/mail_fetch/options.php',
227 'desc' => _("This configures settings for downloading email from a pop3 mailbox to your account on this server."),
228 'js' => false
229 );
230 }
231
165829a3 232?>