[Hastymail-cvs] SF.net SVN: hastymail:[1392] trunk/hastymail2/plugins/pop_fetch
Brought to you by:
sailfrog,
slushpupie
From: <sai...@us...> - 2010-03-26 01:01:18
|
Revision: 1392 http://hastymail.svn.sourceforge.net/hastymail/?rev=1392&view=rev Author: sailfrog Date: 2010-03-26 01:01:11 +0000 (Fri, 26 Mar 2010) Log Message: ----------- more mail fetch plugin updates Modified Paths: -------------- trunk/hastymail2/plugins/pop_fetch/config.php trunk/hastymail2/plugins/pop_fetch/display.php trunk/hastymail2/plugins/pop_fetch/page.php trunk/hastymail2/plugins/pop_fetch/pop3_class.php trunk/hastymail2/plugins/pop_fetch/work.php Added Paths: ----------- trunk/hastymail2/plugins/pop_fetch/ajax.php Added: trunk/hastymail2/plugins/pop_fetch/ajax.php =================================================================== --- trunk/hastymail2/plugins/pop_fetch/ajax.php (rev 0) +++ trunk/hastymail2/plugins/pop_fetch/ajax.php 2010-03-26 01:01:11 UTC (rev 1392) @@ -0,0 +1,33 @@ +<?php + +/* ajax.php: Plugin file responsible for handling ajax callbacks + Copyright (C) 2002-2010 Hastymail Development group + + This file is part of Hastymail. + + Hastymail is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Hastymail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Hastymail; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +* $Id:$ +*/ +function ajax_pop_fetch_fetch_mail($tools) { + require_once('pop3_class.php'); + $accounts = $tools->get_setting('pop_fetch_accounts'); + $res = 0; + foreach ($accounts as $vals) { + $res += count(pop3_session($tools, $vals[6], $vals[7], $vals[3], $vals[2], $vals[4], $vals[5], $vals[9], $vals[8])); + } + return $res; +} +?> Property changes on: trunk/hastymail2/plugins/pop_fetch/ajax.php ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/hastymail2/plugins/pop_fetch/config.php =================================================================== --- trunk/hastymail2/plugins/pop_fetch/config.php 2010-03-25 21:08:06 UTC (rev 1391) +++ trunk/hastymail2/plugins/pop_fetch/config.php 2010-03-26 01:01:11 UTC (rev 1392) @@ -24,7 +24,7 @@ $pop_fetch_hooks = array( 'work_hooks' => array('init'), - 'display_hooks' => array('menu'), + 'display_hooks' => array('menu', 'folder_list_bottom'), 'page_hook' => true, ); $pop_fetch_langs = array( Modified: trunk/hastymail2/plugins/pop_fetch/display.php =================================================================== --- trunk/hastymail2/plugins/pop_fetch/display.php 2010-03-25 21:08:06 UTC (rev 1391) +++ trunk/hastymail2/plugins/pop_fetch/display.php 2010-03-26 01:01:11 UTC (rev 1392) @@ -25,3 +25,10 @@ function pop_fetch_menu($tools) { return ' <a class="pop_fetch_link" href="?page=pop_fetch">Fetch</a> '; } +function pop_fetch_folder_list_bottom($tools) { + if ($tools->get_setting('pop_folder_tree')) { + return '<div id="fetch_link" style="padding-bottom: 5px;"><a onclick="fetch_mail(); return false;" '. + 'style="font-size: 80%; padding-left: 30px;" href="'.$tools->get_url(). + '">Fetch Mail</a></div>'; + } +} Modified: trunk/hastymail2/plugins/pop_fetch/page.php =================================================================== --- trunk/hastymail2/plugins/pop_fetch/page.php 2010-03-25 21:08:06 UTC (rev 1391) +++ trunk/hastymail2/plugins/pop_fetch/page.php 2010-03-26 01:01:11 UTC (rev 1392) @@ -62,13 +62,15 @@ $pd['pop_account_user'] = $atts[6]; $pd['pop_account_password'] = $atts[7]; $pd['pop_account_folder'] = $atts[8]; - $pd['pop_account_keep'] = $atts[9]; if ($atts[4]) { $pd['pop_account_ssl'] = 'checked="checked"'; } if ($atts[5]) { $pd['pop_account_starttls'] = 'checked="checked"'; } + if ($atts[9]) { + $pd['pop_account_keep'] = 'checked="checked"'; + } } elseif (!isset($post['delete_pop_account'])) { $tools->send_notice('Could not the requested account'); @@ -77,6 +79,20 @@ /* update general settings */ if (isset($post['update_pop_fetch'])) { + if (isset($post['account_update_interval']) && intval($post['account_update_interval']) > 0 && + intval($post['account_update_interval']) <= 60*60) { + $tools->save_setting('pop_update_interval', intval($post['account_update_interval'])); + } + else { + $tools->save_setting('pop_update_interval', 0); + } + if (isset($post['account_folder_tree'])) { + $tools->save_setting('pop_folder_tree', 1); + } + else { + $tools->save_setting('pop_folder_tree', 0); + } + $tools->send_notice('Settings Updated'); } /* delete an account */ @@ -317,6 +333,14 @@ } } } + $pd['account_update_interval'] = $tools->get_setting('pop_update_interval'); + $fetch_link = $tools->get_setting('pop_folder_tree'); + if ($fetch_link) { + $pd['account_folder_tree'] = 'checked="checked"'; + } + else { + $pd['account_folder_tree'] = ''; + } $pd['folder_options'] = $tools->print_folder_dropdown($folders, array($pd['pop_account_folder']), true); $pd['pop_accounts'] = $pop_accounts; foreach ($pd['notices'] as $notice) { @@ -403,10 +427,14 @@ <div><b>Fetch Options</b></div> <form method="post" action="?page=pop_fetch"> <table class="fetch_form"> - <tr><td class="opt_leftcol">Show fetch link on the folder tree</td><td><input type="checkbox" name="account_folder_tree" /></td></tr> + <tr><td class="opt_leftcol">Show fetch link on the folder tree</td><td><input type="checkbox" name="account_folder_tree" '.$pd['account_folder_tree'].' /></td></tr> <tr><td class="opt_leftcol">Automatically fetch mail</td><td><select name="account_update_interval">'; foreach ($intervals as $i => $v) { - $data .= '<option value="'.$i.'">'.$v.'</option>'; + $data .= '<option '; + if ($pd['account_update_interval'] == $i) { + $data .= 'selected="selected" '; + } + $data .= 'value="'.$i.'">'.$v.'</option>'; } $data .= '</select></td></tr> <tr><td class="opt_leftcol"><br /><input type="submit" name="update_pop_fetch" value="Update" /></td></tr> Modified: trunk/hastymail2/plugins/pop_fetch/pop3_class.php =================================================================== --- trunk/hastymail2/plugins/pop_fetch/pop3_class.php 2010-03-25 21:08:06 UTC (rev 1391) +++ trunk/hastymail2/plugins/pop_fetch/pop3_class.php 2010-03-26 01:01:11 UTC (rev 1392) @@ -128,10 +128,11 @@ } /* output debug */ function puke() { - echo '<div style="margin: 20px;">'; - echo '<b>POP3 commands</b><br />'.timer_display($this->commands); - echo '<b>POP3 responses</b><br />'.timer_display($this->short_responses); - echo '<div>'; + $res = '<div style="margin: 20px;">'; + $res .= '<b>POP3 commands</b><br />'.timer_display($this->commands); + $res .= '<b>POP3 responses</b><br />'.timer_display($this->short_responses); + $res .= '<div>'; + return $res; } /* check the POP3 response code for errors */ function is_error($response) { @@ -246,4 +247,21 @@ } } +function pop3_session($tools, $user, $pass, $port, $host, $ssl, $starttls, $keep, $destination) { + $pop3 = hm_new('pop3'); + $pop3->server = $host; + $pop3->port = $port; + $pop3->starttls = $starttls; + $pop3->ssl = $ssl; + $msg_list = array(); + if ($pop3->connect()) { + if ($pop3->auth($user, $pass)) { + $msg_list = $pop3->mlist(); + $pop3->rset(); + $pop3->quit(); + //$pop3->puke(); + } + } + return $msg_list; +} ?> Modified: trunk/hastymail2/plugins/pop_fetch/work.php =================================================================== --- trunk/hastymail2/plugins/pop_fetch/work.php 2010-03-25 21:08:06 UTC (rev 1391) +++ trunk/hastymail2/plugins/pop_fetch/work.php 2010-03-26 01:01:11 UTC (rev 1392) @@ -24,20 +24,22 @@ function pop_fetch_init($tools) { require_once('pop3_class.php'); -} -function pop3_session($user, $pass, $port, $host, $ssl, $starttls) { - $pop3 = hm_new('pop3'); - $pop3->server = $host; - $pop3->port = $port; - $pop3->starttls = $starttls; - $pop3->ssl = $ssl; - if ($pop3->connect()) { - if ($pop3->auth($user, $pass)) { - $msg_list = $pop3->mlist(); - $pop3->rset(); - $pop3->quit(); - $pop3->puke(); + $tools->register_ajax_callback('fetch_mail', 0, false); + $tools->add_inline_js(' + function fetch_mail() { + document.getElementById("fetch_link").innerHTML = "<i style=\"font-size: 80%; '. + 'padding-left: 30px;\">Fetching messages...</i>"; + hm_ajax_pop_fetch_fetch_mail(); + return false; } - } + function revert_fetch_link() { + document.getElementById("fetch_link").innerHTML = "<a onclick=\"fetch_mail(); '. + 'return false;\" style=\"font-size: 80%; padding-left: 30px;\" href=\"'.$tools->get_url().'\">Fetch Mail</a>"; + } + function callback_pop_fetch_fetch_mail(output) { + document.getElementById("fetch_link").innerHTML = "<span style=\"font-weight: bold; font-size: 80%; padding-left: 30px;\">New Messages: " + output + "</span>"; + setTimeout(revert_fetch_link, 3000); + } + '); } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |