Commit 4ac419f4 authored by Brendan Cully's avatar Brendan Cully

Teach pop driver about mutt_progress_bar. Allow progress bar to omit total

size if zero (=unknown).
parent 1c7fbc7b
......@@ -350,7 +350,8 @@ void mutt_progress_bar (progress_t* progress, long pos)
if (!NetInc)
mutt_message (progress->msg);
else {
mutt_pretty_size (progress->sizestr, sizeof (progress->sizestr), progress->size);
if (progress->size)
mutt_pretty_size (progress->sizestr, sizeof (progress->sizestr), progress->size);
progress->pos = 0;
}
}
......@@ -363,7 +364,10 @@ void mutt_progress_bar (progress_t* progress, long pos)
progress->pos = pos;
pos = pos / (NetInc << 10) * (NetInc << 10);
mutt_pretty_size (posstr, sizeof (posstr), pos);
mutt_message ("%s %s/%s", progress->msg, posstr, progress->sizestr);
if (progress->size)
mutt_message ("%s %s/%s", progress->msg, posstr, progress->sizestr);
else
mutt_message ("%s %s", progress->msg, posstr);
}
}
#endif
......
......@@ -21,6 +21,7 @@
#endif
#include "mutt.h"
#include "mutt_curses.h"
#include "mx.h"
#include "pop.h"
#include "mutt_crypt.h"
......@@ -341,7 +342,7 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
void *uidl;
char buf[LONG_STRING];
char path[_POSIX_PATH_MAX];
char *m = _("Fetching message...");
progress_t progressbar;
POP_DATA *pop_data = (POP_DATA *)ctx->data;
POP_CACHE *cache;
HEADER *h = ctx->hdrs[msgno];
......@@ -383,7 +384,9 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
return -1;
}
mutt_message (m);
progressbar.size = h->content->length + h->content->offset - 1;
progressbar.msg = _("Fetching message...");
mutt_progress_bar (&progressbar, 0);
mutt_mktemp (path);
msg->fp = safe_fopen (path, "w+");
......@@ -396,7 +399,7 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
snprintf (buf, sizeof (buf), "RETR %d\r\n", h->refno);
ret = pop_fetch_data (pop_data, buf, m, fetch_message, msg->fp);
ret = pop_fetch_data (pop_data, buf, &progressbar, fetch_message, msg->fp);
if (ret == 0)
break;
......
......@@ -21,6 +21,7 @@
#include "mailbox.h"
#include "mutt_socket.h"
#include "mutt_curses.h"
#define POP_PORT 110
#define POP_SSL_PORT 995
......@@ -96,7 +97,7 @@ int pop_parse_path (const char *, ACCOUNT *);
int pop_connect (POP_DATA *);
int pop_open_connection (POP_DATA *);
int pop_query_d (POP_DATA *, char *, size_t, char *);
int pop_fetch_data (POP_DATA *, char *, char *, int (*funct) (char *, void *), void *);
int pop_fetch_data (POP_DATA *, char *, progress_t *, int (*funct) (char *, void *), void *);
int pop_reconnect (CONTEXT *);
void pop_logout (CONTEXT *);
void pop_error (POP_DATA *, char *);
......
......@@ -455,13 +455,14 @@ int pop_query_d (POP_DATA *pop_data, char *buf, size_t buflen, char *msg)
* -2 - invalid command or execution error,
* -3 - error in funct(*line, *data)
*/
int pop_fetch_data (POP_DATA *pop_data, char *query, char *msg,
int pop_fetch_data (POP_DATA *pop_data, char *query, progress_t *progressbar,
int (*funct) (char *, void *), void *data)
{
char buf[LONG_STRING];
char *inbuf;
char *p;
int ret, chunk, line = 0;
int ret, chunk = 0;
long pos = 0;
size_t lenbuf = 0;
strfcpy (buf, query, sizeof (buf));
......@@ -490,6 +491,7 @@ int pop_fetch_data (POP_DATA *pop_data, char *query, char *msg,
}
strfcpy (inbuf + lenbuf, p, sizeof (buf));
pos += chunk;
if (chunk >= sizeof (buf))
{
......@@ -497,9 +499,8 @@ int pop_fetch_data (POP_DATA *pop_data, char *query, char *msg,
}
else
{
line++;
if (msg && ReadInc && (line % ReadInc == 0))
mutt_message ("%s %d", msg, line);
if (progressbar)
mutt_progress_bar (progressbar, pos);
if (ret == 0 && funct (inbuf, data) < 0)
ret = -3;
lenbuf = 0;
......@@ -537,6 +538,7 @@ int pop_reconnect (CONTEXT *ctx)
{
int ret;
POP_DATA *pop_data = (POP_DATA *)ctx->data;
progress_t progressbar;
if (pop_data->status == POP_CONNECTED)
return 0;
......@@ -550,15 +552,16 @@ int pop_reconnect (CONTEXT *ctx)
ret = pop_open_connection (pop_data);
if (ret == 0)
{
char *msg = _("Verifying message indexes...");
int i;
progressbar.msg = _("Verifying message indexes...");
progressbar.size = 0;
mutt_progress_bar (&progressbar, 0);
for (i = 0; i < ctx->msgcount; i++)
ctx->hdrs[i]->refno = -1;
mutt_message (msg);
ret = pop_fetch_data (pop_data, "UIDL\r\n", msg, check_uidl, ctx);
ret = pop_fetch_data (pop_data, "UIDL\r\n", &progressbar, check_uidl, ctx);
if (ret == -2)
{
mutt_error ("%s", pop_data->err_msg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment