Index: pontomail.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/pontomail/pontomail.module,v
retrieving revision 1.26
diff -u -r1.26 pontomail.module
--- pontomail.module 21 Aug 2006 09:02:22 -0000 1.26
+++ pontomail.module 23 Aug 2006 16:01:52 -0000
@@ -132,6 +132,7 @@
* @return block HTML
*/
function pontomail_block($op = 'list', $delta = 0) {
+ global $user;
// listing of blocks such as on the admin/block page
if($op == 'list') {
$block[0]['info'] = t('Mailboxes');
@@ -141,7 +142,34 @@
switch($delta) {
case 0:
$block['subject'] = 'Mail View';
- $block['content'] = 'Mail Content';
+ //$block['content'] = 'Mail Content';
+ $imap = new IMAPService();
+ $accounts = db_query('SELECT * FROM {pontomail_servers} WHERE uid = %d AND enabled = 1', $user->uid);
+ while($row = db_fetch_object($accounts)) {
+ $items[] = array('path' => 'pontomail/viewmailbox/accounts/' . $row->sid, 'title' => $row->server_name);
+ if((arg(1) == 'viewmailbox' || arg(0) == 'pontomail') && arg(3) == $row->sid) {
+ $block['content'] .= '
'. l($row->server_name, 'pontomail/viewmailbox/accounts/'. $row->sid) .''."\n";
+ // List Subscribed Mail Boxes for this Account
+ $imap->connect($row->server_address, $row->server_port, $row->user, $row->password, "", (array)($row));
+ $block['content'] .= ''."\n";
+ if($imap->open()) {
+ $subs = $imap->get_subscriptions();
+ foreach ($subs as $key => $folder) {
+ $folders[] = $imap->get_folder_name($folder->name);
+ }
+ sort($folders);
+ $curbox = 0;
+ while ($curbox < count($folders)) {
+ $block['content'] .= _pontomail_compute_folder_children($row->sid, $imap, $folders, $subs[0]->delimiter, $curbox);
+ }
+ }
+ $block['content'] .= '
'."\n";
+ }
+ else {
+ $block['content'] .= ''. l($row->server_name, 'pontomail/viewmailbox/accounts/'. $row->sid) .''."\n";
+ }
+ }
+ $block['content'] = "\n".''."\n";
break;
case 1:
$block['subject'] = '2Mail View';
@@ -152,6 +180,58 @@
}
} // end function pontomail_block
+/**
+ * Recurent function generates folder list.
+ * $account imap account number
+ * $imap imap connection
+ * @folders folder namesn
+ * $delimiter separates folder names
+ * $parbox number of current box
+ * $return folder list HTML
+ */
+function _pontomail_compute_folder_children($account, $imap, $folders, $delimiter, &$parbox) {
+ $nextbox = $parbox + 1;
+ $childs = '';
+ while (($nextbox < count($folders)) && (_pontomail_is_parent_folder($delimiter, $folders[$nextbox], $folders[$parbox]))) {
+ $childs .= _pontomail_compute_folder_children($account, $imap, $folders, $delimiter, $nextbox);
+ }
+ $curparts = explode($delimiter, $folders[$parbox]);
+ $real_name = $curparts[count($curparts)-1];
+ $folder_status = $imap->folder_status($folders[$parbox]);
+ if ($folder_status->rescent > 0 || $folder_status->unseen > 0) {
+ $string = $real_name .' ('. $folder_status->unseen .')';
+ }
+ else {
+ $string = $real_name;
+ }
+ $string = l($string, 'pontomail/viewmailbox/accounts/'. $account .'/'. $folders[$parbox]);
+ if ($childs) {
+ $string = ''. $string .''."\n".''."\n";
+ }
+ else {
+ $string = ''. $string .''."\n";
+ }
+ $parbox = $nextbox;
+ return $string;
+
+}
+
+/**
+ * Compares imap folder names to check if one folder is child of the other.
+ * $delimiter separates folder names
+ * $curbox_name name of the next folder
+ * $parbox_name name of the current folder
+ * $return true if one folder is child of the other
+ */
+function _pontomail_is_parent_folder($delimiter, $curbox_name, $parbox_name) {
+ $curparts = explode($delimiter, $curbox_name);
+ $curname = array_pop($curparts);
+ $actual_parname = implode($delimiter, $curparts);
+ $actual_parname = substr($actual_parname,0,strlen($parbox_name));
+
+ return ($parbox_name == $actual_parname);
+}
+
function _pontomail_admin() {
$output .= 'Current Extentions