Report when idle
This commit is contained in:
parent
a2ff8bab25
commit
97ee60c3cb
|
@ -66,7 +66,7 @@ typedef enum _AccountStatus
|
||||||
AS_CONNECTED,
|
AS_CONNECTED,
|
||||||
AS_DISCONNECTED,
|
AS_DISCONNECTED,
|
||||||
AS_AUTHENTICATED,
|
AS_AUTHENTICATED,
|
||||||
AS_READY
|
AS_IDLE
|
||||||
} AccountStatus;
|
} AccountStatus;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -441,6 +441,8 @@ static int _account_helper_error(Account * account, char const * message,
|
||||||
|
|
||||||
|
|
||||||
/* account_helper_event */
|
/* account_helper_event */
|
||||||
|
static void _helper_event_status(Account * account, AccountEvent * event);
|
||||||
|
|
||||||
static void _account_helper_event(Account * account, AccountEvent * event)
|
static void _account_helper_event(Account * account, AccountEvent * event)
|
||||||
{
|
{
|
||||||
Mailer * mailer = account->mailer;
|
Mailer * mailer = account->mailer;
|
||||||
|
@ -451,11 +453,30 @@ static void _account_helper_event(Account * account, AccountEvent * event)
|
||||||
mailer_error(mailer, event->error.message, 1);
|
mailer_error(mailer, event->error.message, 1);
|
||||||
break;
|
break;
|
||||||
case AET_STATUS:
|
case AET_STATUS:
|
||||||
mailer_set_status(mailer, event->status.message);
|
_helper_event_status(account, event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _helper_event_status(Account * account, AccountEvent * event)
|
||||||
|
{
|
||||||
|
Mailer * mailer = account->mailer;
|
||||||
|
char const * message = event->status.message;
|
||||||
|
|
||||||
|
if(message == NULL)
|
||||||
|
switch(event->status.status)
|
||||||
|
{
|
||||||
|
case AS_IDLE:
|
||||||
|
message = "Ready";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(message == NULL)
|
||||||
|
return;
|
||||||
|
mailer_set_status(mailer, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* account_helper_authenticate */
|
/* account_helper_authenticate */
|
||||||
static char * _account_helper_authenticate(Account * account,
|
static char * _account_helper_authenticate(Account * account,
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
/* FIXME:
|
/* FIXME:
|
||||||
* - do not erroneously parse body/header data as potential command completion
|
* - do not erroneously parse body/header data as potential command completion
|
||||||
|
* - do not fetch messages when there are none available in the first place
|
||||||
* - openssl should be more explicit when SSL_set_fd() is missing (no BIO)
|
* - openssl should be more explicit when SSL_set_fd() is missing (no BIO)
|
||||||
* - support multiple connections? */
|
* - support multiple connections? */
|
||||||
|
|
||||||
|
@ -198,6 +199,10 @@ static int _imap4_lookup(IMAP4 * imap4, char const * hostname, uint16_t port,
|
||||||
static int _imap4_parse(IMAP4 * imap4);
|
static int _imap4_parse(IMAP4 * imap4);
|
||||||
static void _imap4_reset(IMAP4 * imap4);
|
static void _imap4_reset(IMAP4 * imap4);
|
||||||
|
|
||||||
|
/* events */
|
||||||
|
static void _imap4_event_status(IMAP4 * imap4, AccountStatus status,
|
||||||
|
char const * message);
|
||||||
|
|
||||||
/* folders */
|
/* folders */
|
||||||
static AccountFolder * _imap4_folder_new(IMAP4 * imap4, AccountFolder * parent,
|
static AccountFolder * _imap4_folder_new(IMAP4 * imap4, AccountFolder * parent,
|
||||||
char const * name);
|
char const * name);
|
||||||
|
@ -792,6 +797,21 @@ static void _imap4_reset(IMAP4 * imap4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* imap4_event_status */
|
||||||
|
static void _imap4_event_status(IMAP4 * imap4, AccountStatus status,
|
||||||
|
char const * message)
|
||||||
|
{
|
||||||
|
AccountPluginHelper * helper = imap4->helper;
|
||||||
|
AccountEvent event;
|
||||||
|
|
||||||
|
memset(&event, 0, sizeof(event));
|
||||||
|
event.status.type = AET_STATUS;
|
||||||
|
event.status.status = status;
|
||||||
|
event.status.message = message;
|
||||||
|
helper->event(helper->account, &event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* imap4_folder_new */
|
/* imap4_folder_new */
|
||||||
static AccountFolder * _imap4_folder_new(IMAP4 * imap4, AccountFolder * parent,
|
static AccountFolder * _imap4_folder_new(IMAP4 * imap4, AccountFolder * parent,
|
||||||
char const * name)
|
char const * name)
|
||||||
|
@ -944,7 +964,6 @@ static gboolean _on_connect(gpointer data)
|
||||||
{
|
{
|
||||||
IMAP4 * imap4 = data;
|
IMAP4 * imap4 = data;
|
||||||
AccountPluginHelper * helper = imap4->helper;
|
AccountPluginHelper * helper = imap4->helper;
|
||||||
AccountEvent event;
|
|
||||||
char const * hostname;
|
char const * hostname;
|
||||||
char const * p;
|
char const * p;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
@ -982,13 +1001,9 @@ static gboolean _on_connect(gpointer data)
|
||||||
/* ignore this error */
|
/* ignore this error */
|
||||||
helper->error(NULL, strerror(errno), 1);
|
helper->error(NULL, strerror(errno), 1);
|
||||||
/* report the current status */
|
/* report the current status */
|
||||||
memset(&event, 0, sizeof(event));
|
|
||||||
event.status.type = AET_STATUS;
|
|
||||||
event.status.status = AS_CONNECTING;
|
|
||||||
snprintf(buf, sizeof(buf), "Connecting to %s (%s:%u)", hostname,
|
snprintf(buf, sizeof(buf), "Connecting to %s (%s:%u)", hostname,
|
||||||
inet_ntoa(sa.sin_addr), port);
|
inet_ntoa(sa.sin_addr), port);
|
||||||
event.status.message = buf;
|
_imap4_event_status(imap4, AS_CONNECTING, buf);
|
||||||
helper->event(helper->account, &event);
|
|
||||||
/* connect to the remote host */
|
/* connect to the remote host */
|
||||||
if((connect(imap4->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0
|
if((connect(imap4->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0
|
||||||
&& errno != EINPROGRESS)
|
&& errno != EINPROGRESS)
|
||||||
|
@ -1059,7 +1074,6 @@ static gboolean _on_watch_can_connect(GIOChannel * source,
|
||||||
{
|
{
|
||||||
IMAP4 * imap4 = data;
|
IMAP4 * imap4 = data;
|
||||||
AccountPluginHelper * helper = imap4->helper;
|
AccountPluginHelper * helper = imap4->helper;
|
||||||
AccountEvent event;
|
|
||||||
char const * hostname = imap4->config[I4CV_HOSTNAME].value;
|
char const * hostname = imap4->config[I4CV_HOSTNAME].value;
|
||||||
uint16_t port = (unsigned long)imap4->config[I4CV_PORT].value;
|
uint16_t port = (unsigned long)imap4->config[I4CV_PORT].value;
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
|
@ -1074,14 +1088,9 @@ static gboolean _on_watch_can_connect(GIOChannel * source,
|
||||||
/* XXX remember the address instead */
|
/* XXX remember the address instead */
|
||||||
if(_imap4_lookup(imap4, hostname, port, &sa) == 0)
|
if(_imap4_lookup(imap4, hostname, port, &sa) == 0)
|
||||||
{
|
{
|
||||||
/* report the current status */
|
|
||||||
memset(&event, 0, sizeof(event));
|
|
||||||
event.status.type = AET_STATUS;
|
|
||||||
event.status.status = AS_CONNECTED;
|
|
||||||
snprintf(buf, sizeof(buf), "Connected to %s (%s:%u)",
|
snprintf(buf, sizeof(buf), "Connected to %s (%s:%u)",
|
||||||
hostname, inet_ntoa(sa.sin_addr), port);
|
hostname, inet_ntoa(sa.sin_addr), port);
|
||||||
event.status.message = buf;
|
_imap4_event_status(imap4, AS_CONNECTED, buf);
|
||||||
helper->event(helper->account, &event);
|
|
||||||
}
|
}
|
||||||
imap4->wr_source = 0;
|
imap4->wr_source = 0;
|
||||||
/* setup SSL */
|
/* setup SSL */
|
||||||
|
@ -1245,7 +1254,10 @@ static gboolean _on_watch_can_read(GIOChannel * source, GIOCondition condition,
|
||||||
}
|
}
|
||||||
imap4->rd_source = 0;
|
imap4->rd_source = 0;
|
||||||
if(imap4->queue_cnt == 0)
|
if(imap4->queue_cnt == 0)
|
||||||
|
{
|
||||||
|
_imap4_event_status(imap4, AS_IDLE, NULL);
|
||||||
imap4->source = g_timeout_add(30000, _on_noop, imap4);
|
imap4->source = g_timeout_add(30000, _on_noop, imap4);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
imap4->wr_source = g_io_add_watch(imap4->channel, G_IO_OUT,
|
imap4->wr_source = g_io_add_watch(imap4->channel, G_IO_OUT,
|
||||||
_on_watch_can_write, imap4);
|
_on_watch_can_write, imap4);
|
||||||
|
@ -1318,7 +1330,10 @@ static gboolean _on_watch_can_read_ssl(GIOChannel * source,
|
||||||
}
|
}
|
||||||
imap4->rd_source = 0;
|
imap4->rd_source = 0;
|
||||||
if(imap4->queue_cnt == 0)
|
if(imap4->queue_cnt == 0)
|
||||||
|
{
|
||||||
|
_imap4_event_status(imap4, AS_IDLE, NULL);
|
||||||
imap4->source = g_timeout_add(30000, _on_noop, imap4);
|
imap4->source = g_timeout_add(30000, _on_noop, imap4);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
imap4->wr_source = g_io_add_watch(imap4->channel, G_IO_OUT,
|
imap4->wr_source = g_io_add_watch(imap4->channel, G_IO_OUT,
|
||||||
_on_watch_can_write_ssl, imap4);
|
_on_watch_can_write_ssl, imap4);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user