/[drupal]/contributions/modules/rcmail/rcmail.module
ViewVC logotype

Contents of /contributions/modules/rcmail/rcmail.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Fri Jan 19 21:00:12 2007 UTC (2 years, 10 months ago) by polyformalsp
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 /* $Id: rcmail.module,v 1.3 2006/06/12 10:20:39 polyformalsp Exp $ */
3
4 /**
5 * @file
6 * Integration of the roundcube webmail client in drupal.
7 *
8 */
9
10 /**
11 * Implementation of hook_help().
12 *
13 * Throughout Drupal, hook_help() is used to display help text at the top of
14 * pages. Some other parts of Drupal pages get explanatory text from these hooks
15 * as well. We use it here to provide a description of the module on the
16 * module administration page.
17 */
18 function rcmail_help($section) {
19 switch($section) {
20 case 'admin/modules#description' :
21 return t('integration of roundcubemail IMAP client');
22 default :
23 return;
24 }
25 }
26
27 function rcmail_settings() {
28 // only administrators can access this function
29 if (!user_access('adminster rcmail')) {
30 return message_access();
31 }
32
33 $form["rcmail_iframe_width"] = array(
34 '#type' => 'textfield',
35 '#title' => t("iframe width"),
36 '#default_value' => variable_get("rcmail_iframe_width", "850"),
37 '#size' => 10,
38 '#maxlength' => 15,
39 '#description' => t("Enter width of the iframe. Optimum is 850px"),
40 );
41
42 $form["rcmail_iframe_height"] = array(
43 '#type' => 'textfield',
44 '#title' => t("iframe height"),
45 '#default_value' => variable_get("rcmail_iframe_height", "550"),
46 '#size' => 10,
47 '#maxlength' => 15,
48 '#description' => t("Enter width of the iframe. Optimum is 550px"),
49 );
50 return $form;
51 }
52
53 function rcmail_perm() {
54 return array('use rcmail', 'adminster rcmail');
55 }
56
57 /**
58 * hook_menu() implementation
59 */
60
61
62 /**
63 * Implementation of hook_user().
64 *
65 * Grab the settings of the imap account for each user
66 */
67 function rcmail_user($type, &$edit, &$user, $category = NULL) {
68 switch ($type) {
69 case 'form':
70 if ($category == 'account' && user_access('use rcmail')) {
71 //$user_status = $edit['rcmail_status'] != NULL ? $edit['rcmail_status'] : ($user->rcmail_status != NULL ? $user->rcmail_status : variable_get('rcmail_default_state', 0));
72
73 $dec=_decrypt($edit['rcmail_password']);
74
75 $form['rcmail_settings'] = array(
76 '#type' => 'fieldset',
77 '#title' => t('Roundcubemail Settings for your IMAP account'),
78 '#collapsible' => TRUE,
79 '#weight' => 4);
80
81 $form['rcmail_settings']['rcmail_username'] = array(
82 '#type' => 'textfield',
83 '#title' => t('user'),
84 '#default_value' => $edit['rcmail_username'],
85 '#size' => 20,
86 '#maxlength' => 20,
87 '#description' => t('Enter the username of your IMAP account.'),
88 );
89
90 $form['rcmail_settings']['rcmail_password'] = array(
91 '#type' => 'password',
92 '#title' => t('password'),
93 '#default_value' => $dec,
94 '#size' => 20,
95 '#maxlength' => 20,
96 '#required' => TRUE,
97 '#description' => t('Enter your the password of your IMAP account.'),
98 );
99
100 $form['rcmail_settings']['rcmail_server'] = array(
101 '#type' => 'textfield',
102 '#title' => t('server'),
103 '#default_value' => $edit['rcmail_server'],
104 '#size' => 20,
105 '#maxlength' => 20,
106 '#description' => t('Enter the servername of your IMAP account.'),
107 );
108
109 return $form;
110
111 } //eof if
112
113 case 'update':
114 $edit['rcmail_password'] = _encrypt($edit['rcmail_password']);
115 } //eof switch $type
116 }
117
118 /**
119 * hook_menu() implementation
120 */
121 function rcmail_menu() {
122 $items[] = array(
123 'path' => 'rcmail',
124 'title' => t('roundcubemail'),
125 'callback' => 'rcmail_page',
126 'access' => (user_access('use rcmail'))
127 );
128 return $items;
129 }
130
131
132 /**
133 * callback to return the iframe with roundcube inside
134 */
135 function rcmail_page(){
136 global $user;
137 $height = variable_get("rcmail_iframe_height", "550");
138 $width = variable_get("rcmail_iframe_width", "850");
139 $content='<iframe width="' . $width . '" height="' . $height . '" src="./modules/rcmail/roundcubemail/index.php?do=login">foo</iframe>';
140 print theme('page', $content);
141 }
142
143 /**
144 * decrypt the password of imap account stored in drupals users settings
145 * callback from roundcubemail/index.php
146 * @param $enc
147 * an encrypted string
148 * @return
149 * return the decrypted string
150 */
151 function _decrypt($enc) {
152 $key='zugbz766fhgfv';
153 $enc = base64_decode($enc);
154 $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
155 $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
156 $dec = mcrypt_decrypt(MCRYPT_XTEA, $key, $enc, MCRYPT_MODE_ECB, $iv);
157 return $dec;
158 }
159
160 /**
161 * encrypt the password grabed from the user settings
162 *
163 * @param $dec
164 * an plain text string
165 * @return
166 * return the encrypted string
167 */
168 function _encrypt($dec) {
169 $key='zugbz766fhgfv';
170 $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
171 $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
172 $enc = mcrypt_encrypt(MCRYPT_XTEA, $key, $dec, MCRYPT_MODE_ECB, $iv);
173 $enc = base64_encode($enc);
174 return $enc;
175 }
176
177
178 ?>

  ViewVC Help
Powered by ViewVC 1.1.2