Exemplo n.º 1
0
/* Check for new messages and fetch headers */
int pop_check_mailbox(CONTEXT *ctx, int *index_hint)
{
    int ret;
    POP_DATA *pop_data = (POP_DATA *)ctx->data;

    if ((pop_data->check_time + PopCheckTimeout) > time(NULL))
        return 0;

    pop_logout(ctx);

    mutt_socket_close(pop_data->conn);

    if (pop_open_connection(pop_data) < 0)
        return -1;

    ctx->size = pop_data->size;

    mutt_message _("Checking for new messages...");

    ret = pop_fetch_headers(ctx);
    pop_clear_cache(pop_data);

    if (ret < 0)
        return -1;

    if (ret > 0)
        return M_NEW_MAIL;

    return 0;
}
Exemplo n.º 2
0
/* update POP mailbox - delete messages from server */
int pop_sync_mailbox(CONTEXT *ctx, int *index_hint)
{
    int i, j, ret = 0;
    char buf[LONG_STRING];
    POP_DATA *pop_data = (POP_DATA *)ctx->data;
    progress_t progress;

    pop_data->check_time = 0;

    FOREVER
    {
        if (pop_reconnect(ctx) < 0)
            return -1;

        mutt_progress_init(&progress, _("Marking messages deleted..."),
                           M_PROGRESS_MSG, WriteInc, ctx->deleted);

        for (i = 0, j = 0, ret = 0; ret == 0
             && i < ctx->msgcount; i++) {
            if (ctx->hdrs[i]->deleted
                && (ctx->hdrs[i]->refno != -1)) {
                j++;

                if (!ctx->quiet)
                    mutt_progress_update(&progress, j, -1);
                snprintf(buf, sizeof(buf), "DELE %d\r\n", ctx->hdrs[i]->refno);

                if ((ret = pop_query(pop_data, buf, sizeof(buf))) == 0) {
                    mutt_bcache_del(pop_data->bcache, ctx->hdrs[i]->data);
                }
            }

        }

        if (ret == 0) {
            strfcpy(buf, "QUIT\r\n", sizeof(buf));
            ret = pop_query(pop_data, buf, sizeof(buf));
        }

        if (ret == 0) {
            pop_data->clear_cache = 1;
            pop_clear_cache(pop_data);
            pop_data->status = POP_DISCONNECTED;
            return 0;
        }

        if (ret == -2) {
            mutt_error("%s", pop_data->err_msg);
            mutt_sleep(2);
            return -1;
        }
    }
}
Exemplo n.º 3
0
/* close POP mailbox */
int pop_close_mailbox(CONTEXT *ctx)
{
    POP_DATA *pop_data = (POP_DATA *)ctx->data;

    if (!pop_data)
        return 0;

    pop_logout(ctx);

    if (pop_data->status != POP_NONE)
        mutt_socket_close(pop_data->conn);

    pop_data->status = POP_NONE;

    pop_data->clear_cache = 1;
    pop_clear_cache(pop_data);

    if (!pop_data->conn->data)
        mutt_socket_free(pop_data->conn);

    mutt_bcache_close(&pop_data->bcache);

    return 0;
}
Exemplo n.º 4
0
/* update POP mailbox - delete messages from server */
int pop_sync_mailbox (CONTEXT *ctx, int *index_hint)
{
  int i, j, ret = 0;
  char buf[LONG_STRING];
  POP_DATA *pop_data = (POP_DATA *)ctx->data;
  progress_t progress;
#ifdef USE_HCACHE
  header_cache_t *hc = NULL;
#endif

  pop_data->check_time = 0;

  FOREVER
  {
    if (pop_reconnect (ctx) < 0)
      return -1;

    mutt_progress_init (&progress, _("Marking messages deleted..."),
			M_PROGRESS_MSG, WriteInc, ctx->deleted);

#if USE_HCACHE
    hc = pop_hcache_open (pop_data, ctx->path);
#endif

    for (i = 0, j = 0, ret = 0; ret == 0 && i < ctx->msgcount; i++)
    {
      if (ctx->hdrs[i]->deleted && ctx->hdrs[i]->refno != -1)
      {
	j++;
	if (!ctx->quiet)
	  mutt_progress_update (&progress, j, -1);
	snprintf (buf, sizeof (buf), "DELE %d\r\n", ctx->hdrs[i]->refno);
	if ((ret = pop_query (pop_data, buf, sizeof (buf))) == 0)
	{
	  mutt_bcache_del (pop_data->bcache, ctx->hdrs[i]->data);
#if USE_HCACHE
	  mutt_hcache_delete (hc, ctx->hdrs[i]->data, strlen);
#endif
	}
      }

#if USE_HCACHE
      if (ctx->hdrs[i]->changed)
      {
	mutt_hcache_store (hc, ctx->hdrs[i]->data, ctx->hdrs[i], 0, strlen, M_GENERATE_UIDVALIDITY);
      }
#endif

    }

#if USE_HCACHE
    mutt_hcache_close (hc);
#endif

    if (ret == 0)
    {
      strfcpy (buf, "QUIT\r\n", sizeof (buf));
      ret = pop_query (pop_data, buf, sizeof (buf));
    }

    if (ret == 0)
    {
      pop_data->clear_cache = 1;
      pop_clear_cache (pop_data);
      pop_data->status = POP_DISCONNECTED;
      return 0;
    }

    if (ret == -2)
    {
      mutt_error ("%s", pop_data->err_msg);
      mutt_sleep (2);
      return -1;
    }
  }
}