d622d38a |
1 | <?php |
2 | |
4f51df66 |
3 | /** |
4 | * mail_fetch/functions.php |
5 | * |
6 | * Copyright (c) 1999-2005 The SquirrelMail Project Team |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * Functions for the mailfetch plugin. |
10 | * |
11 | * Original code from LexZEUS <lexzeus@mifinca.com> |
12 | * and josh@superfork.com (extracted from php manual) |
13 | * Adapted for MailFetch by Philippe Mingo <mingo@rotedic.com> |
14 | * |
15 | * @version $Id$ |
16 | * @package plugins |
17 | * @subpackage mail_fetch |
18 | */ |
d622d38a |
19 | |
5f438206 |
20 | /** declare plugin globals */ |
21 | global $mail_fetch_allow_unsubscribed; |
22 | |
23 | /** |
24 | * Controls use of unsubscribed folders in plugin |
25 | * @global boolean $mail_fetch_allow_unsubscribed |
5c89bd63 |
26 | * @since 1.5.1 and 1.4.5 |
5f438206 |
27 | */ |
28 | $mail_fetch_allow_unsubscribed = false; |
29 | |
4f51df66 |
30 | /** |
31 | * hex2bin - document me |
32 | */ |
33 | function hex2bin( $data ) { |
d622d38a |
34 | |
4f51df66 |
35 | /* Original code by josh@superfork.com */ |
d622d38a |
36 | |
4f51df66 |
37 | $len = strlen($data); |
38 | $newdata = ''; |
39 | for( $i=0; $i < $len; $i += 2 ) { |
40 | $newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) ); |
d622d38a |
41 | } |
4f51df66 |
42 | return $newdata; |
43 | } |
d622d38a |
44 | |
4f51df66 |
45 | function mf_keyED( $txt ) { |
d622d38a |
46 | |
4f51df66 |
47 | global $MF_TIT; |
d622d38a |
48 | |
4f51df66 |
49 | if( !isset( $MF_TIT ) ) { |
50 | $MF_TIT = "MailFetch Secure for SquirrelMail 1.x"; |
51 | } |
d622d38a |
52 | |
4f51df66 |
53 | $encrypt_key = md5( $MF_TIT ); |
54 | $ctr = 0; |
55 | $tmp = ""; |
56 | for( $i = 0; $i < strlen( $txt ); $i++ ) { |
57 | if( $ctr == strlen( $encrypt_key ) ) $ctr=0; |
58 | $tmp.= substr( $txt, $i, 1 ) ^ substr( $encrypt_key, $ctr, 1 ); |
59 | $ctr++; |
d622d38a |
60 | } |
4f51df66 |
61 | return $tmp; |
62 | } |
d622d38a |
63 | |
4f51df66 |
64 | function encrypt( $txt ) { |
d622d38a |
65 | |
4f51df66 |
66 | srand( (double) microtime() * 1000000 ); |
67 | $encrypt_key = md5( rand( 0, 32000 ) ); |
68 | $ctr = 0; |
69 | $tmp = ""; |
70 | for( $i = 0; $i < strlen( $txt ); $i++ ) { |
d622d38a |
71 | if ($ctr==strlen($encrypt_key)) $ctr=0; |
4f51df66 |
72 | $tmp.= substr($encrypt_key,$ctr,1) . |
73 | (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); |
d622d38a |
74 | $ctr++; |
d622d38a |
75 | } |
4f51df66 |
76 | return bin2hex( mf_keyED( $tmp ) ); |
77 | |
78 | } |
d622d38a |
79 | |
4f51df66 |
80 | function decrypt( $txt ) { |
d622d38a |
81 | |
4f51df66 |
82 | $txt = mf_keyED( hex2bin( $txt ) ); |
83 | $tmp = ''; |
84 | for ( $i=0; $i < strlen( $txt ); $i++ ) { |
85 | $md5 = substr( $txt, $i, 1 ); |
86 | $i++; |
87 | $tmp.= ( substr( $txt, $i, 1 ) ^ $md5 ); |
d622d38a |
88 | } |
4f51df66 |
89 | return $tmp; |
90 | } |
d622d38a |
91 | |
5f438206 |
92 | /** |
93 | * check mail folder |
94 | * @param stream $imap_stream imap connection resource |
95 | * @param string $imap_folder imap folder name |
96 | * @return boolean true, when folder can be used to store messages. |
5c89bd63 |
97 | * @since 1.5.1 and 1.4.5 |
5f438206 |
98 | */ |
99 | function mail_fetch_check_folder($imap_stream,$imap_folder) { |
100 | global $mail_fetch_allow_unsubscribed; |
101 | |
102 | // check if folder is subscribed or only exists. |
103 | if (sqimap_mailbox_is_subscribed($imap_stream,$imap_folder)) { |
104 | $ret = true; |
105 | } elseif ($mail_fetch_allow_unsubscribed && sqimap_mailbox_exists($imap_stream,$imap_folder)) { |
106 | $ret = true; |
107 | } else { |
108 | $ret = false; |
109 | } |
110 | |
111 | // make sure that folder can store messages |
112 | if ($ret && mail_fetch_check_noselect($imap_stream,$imap_folder)) { |
113 | $ret = false; |
114 | } |
115 | |
116 | return $ret; |
117 | } |
118 | |
119 | /** |
120 | * Checks if folder is noselect (can't store messages) |
f8a1ed5a |
121 | * |
5f438206 |
122 | * Function does not check if folder subscribed. |
123 | * @param stream $imap_stream imap connection resource |
124 | * @param string $imap_folder imap folder name |
125 | * @return boolean true, when folder has noselect flag. false in any other case. |
5c89bd63 |
126 | * @since 1.5.1 and 1.4.5 |
5f438206 |
127 | */ |
128 | function mail_fetch_check_noselect($imap_stream,$imap_folder) { |
129 | $boxes=sqimap_mailbox_list($imap_stream); |
130 | foreach($boxes as $box) { |
131 | if ($box['unformatted']==$imap_folder) { |
132 | return (bool) check_is_noselect($box['raw']); |
133 | } |
134 | } |
135 | return false; |
136 | } |
91e0dccc |
137 | ?> |