Example #1
0
/* mutt_conn_find: find a connection off the list of connections whose
 *   account matches account. If start is not null, only search for
 *   connections after the given connection (allows higher level socket code
 *   to make more fine-grained searches than account info - eg in IMAP we may
 *   wish to find a connection which is not in IMAP_SELECTED state) */
CONNECTION* mutt_conn_find (const CONNECTION* start, const ACCOUNT* account)
{
  CONNECTION* conn;
  ciss_url_t url;
  char hook[LONG_STRING];

  /* account isn't actually modified, since url isn't either */
  mutt_account_tourl ((ACCOUNT*) account, &url);
  url.path = NULL;
  url_ciss_tostring (&url, hook, sizeof (hook), 0);
#ifndef LIBMUTT /* no mutt hooks */
  mutt_account_hook (hook);
#endif 
  conn = start ? start->next : Connections;
  while (conn)
  {
    if (mutt_account_match (account, &(conn->account)))
      return conn;
    conn = conn->next;
  }

  conn = socket_new_conn ();
  memcpy (&conn->account, account, sizeof (ACCOUNT));

  conn->next = Connections;
  Connections = conn;

  if (Tunnel && *Tunnel)
#ifndef LIBMUTT
    mutt_tunnel_socket_setup (conn);
#else
  {} 
#endif
  else if (account->flags & M_ACCT_SSL) 
Example #2
0
/* imap_qualify_path: make an absolute IMAP folder target, given IMAP_MBOX
 *   and relative path. */
void imap_qualify_path (char *dest, size_t len, IMAP_MBOX * mx, char *path)
{
  ciss_url_t url;

  mutt_account_tourl (&mx->account, &url);
  url.path = path;

  url_ciss_tostring (&url, dest, len, 0);
}
Example #3
0
static header_cache_t *pop_hcache_open (POP_DATA *pop_data, const char *path)
{
  ciss_url_t url;
  char p[LONG_STRING];

  if (!pop_data || !pop_data->conn)
    return mutt_hcache_open (HeaderCache, path, NULL);

  mutt_account_tourl (&pop_data->conn->account, &url);
  url.path = HC_FNAME;
  url_ciss_tostring (&url, p, sizeof (p), U_PATH);
  return mutt_hcache_open (HeaderCache, p, pop_hcache_namer);
}
Example #4
0
/* imap_pretty_mailbox: called by mutt_pretty_mailbox to make IMAP paths
 *   look nice. */
void imap_pretty_mailbox (char* path)
{
  IMAP_MBOX home, target;
  ciss_url_t url;
  char* delim;
  int tlen;
  int hlen = 0;
  char home_match = 0;

  if (imap_parse_path (path, &target) < 0)
    return;

  tlen = mutt_strlen (target.mbox);
  /* check whether we can do '=' substitution */
  if (mx_is_imap(Maildir) && !imap_parse_path (Maildir, &home))
  {
    hlen = mutt_strlen (home.mbox);
    if (tlen && mutt_account_match (&home.account, &target.account) &&
	!mutt_strncmp (home.mbox, target.mbox, hlen))
    {
      if (! hlen)
	home_match = 1;
      else if (ImapDelimChars)
	for (delim = ImapDelimChars; *delim != '\0'; delim++)
	  if (target.mbox[hlen] == *delim)
	    home_match = 1;
    }
    FREE (&home.mbox);
  }

  /* do the '=' substitution */
  if (home_match) {
    *path++ = '=';
    /* copy remaining path, skipping delimiter */
    if (! hlen)
      hlen = -1;
    memcpy (path, target.mbox + hlen + 1, tlen - hlen - 1);
    path[tlen - hlen - 1] = '\0';
  }
  else
  {
    mutt_account_tourl (&target.account, &url);
    url.path = target.mbox;
    /* FIXME: That hard-coded constant is bogus. But we need the actual
     *   size of the buffer from mutt_pretty_mailbox. And these pretty
     *   operations usually shrink the result. Still... */
    url_ciss_tostring (&url, path, 1024, 0);
  }

  FREE (&target.mbox);
}
Example #5
0
/* mutt_conn_find: find a connection off the list of connections whose
 *   account matches account. If start is not null, only search for
 *   connections after the given connection (allows higher level socket code
 *   to make more fine-grained searches than account info - eg in IMAP we may
 *   wish to find a connection which is not in IMAP_SELECTED state) */
CONNECTION* mutt_conn_find (const CONNECTION* start, const ACCOUNT* account)
{
        CONNECTION* conn;
        ciss_url_t url;
        char hook[LONG_STRING];

/* account isn't actually modified, since url isn't either */
        mutt_account_tourl ((ACCOUNT*) account, &url);
        url.path = NULL;
        url_ciss_tostring (&url, hook, sizeof (hook), 0);
        mutt_account_hook (hook);

        conn = start ? start->next : Connections;
        while (conn) {
                if (mutt_account_match (account, &(conn->account)))
                        return conn;
                conn = conn->next;
        }

        conn = socket_new_conn ();
        memcpy (&conn->account, account, sizeof (ACCOUNT));

        conn->next = Connections;
        Connections = conn;

        if (Tunnel && *Tunnel)
                mutt_tunnel_socket_setup (conn);
        else if (account->flags & M_ACCT_SSL) {
#if defined(USE_SSL)
                if (mutt_ssl_socket_setup (conn) < 0) {
                        mutt_socket_free (conn);
                        return NULL;
                }
#else
                mutt_error _("SSL is unavailable.");
                mutt_sleep (2);
                mutt_socket_free (conn);

                return NULL;
#endif
        }
        else {
                conn->conn_read = raw_socket_read;
                conn->conn_write = raw_socket_write;
                conn->conn_open = raw_socket_open;
                conn->conn_close = raw_socket_close;
                conn->conn_poll = raw_socket_poll;
        }

        return conn;
}
Example #6
0
/* imap_expand_path: IMAP implementation of mutt_expand_path. Rewrite
 *   an IMAP path in canonical and absolute form.
 * Inputs: a buffer containing an IMAP path, and the number of bytes in
 *   that buffer.
 * Outputs: The buffer is rewritten in place with the canonical IMAP path.
 * Returns 0 on success, or -1 if imap_parse_path chokes or url_ciss_tostring
 *   fails, which it might if there isn't enough room in the buffer. */
int imap_expand_path (char *path, size_t len)
{
  IMAP_MBOX mx;
  ciss_url_t url;
  int rc;

  if (imap_parse_path (path, &mx) < 0)
    return -1;

  mutt_account_tourl (&mx.account, &url);
  url.path = mx.mbox;

  rc = url_ciss_tostring (&url, path, len, U_DECODE_PASSWD);
  mem_free (&mx.mbox);

  return rc;
}
Example #7
0
/* imap_expand_path: IMAP implementation of mutt_expand_path. Rewrite
 *   an IMAP path in canonical and absolute form.
 * Inputs: a buffer containing an IMAP path, and the number of bytes in
 *   that buffer.
 * Outputs: The buffer is rewritten in place with the canonical IMAP path.
 * Returns 0 on success, or -1 if imap_parse_path chokes or url_ciss_tostring
 *   fails, which it might if there isn't enough room in the buffer. */
int imap_expand_path (char* path, size_t len)
{
  IMAP_MBOX mx;
  IMAP_DATA* idata;
  ciss_url_t url;
  char fixedpath[LONG_STRING];
  int rc;

  if (imap_parse_path (path, &mx) < 0)
    return -1;

  idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW);
  mutt_account_tourl (&mx.account, &url);
  imap_fix_path (idata, mx.mbox, fixedpath, sizeof (fixedpath));
  url.path = fixedpath;

  rc = url_ciss_tostring (&url, path, len, U_DECODE_PASSWD);
  FREE (&mx.mbox);

  return rc;
}
Example #8
0
static int bcache_path(ACCOUNT *account, const char *mailbox,
		       char *dst, size_t dstlen)
{
  char host[STRING];
  char path[_POSIX_PATH_MAX];
  ciss_url_t url;
  int len;

  if (!account || !MessageCachedir || !*MessageCachedir || !dst || !dstlen)
    return -1;

  /* make up a ciss_url_t we can turn into a string */
  memset (&url, 0, sizeof (ciss_url_t));
  mutt_account_tourl (account, &url);
  /*
   * mutt_account_tourl() just sets up some pointers;
   * if this ever changes, we have a memleak here
   */
  url.path = NULL;
  if (url_ciss_tostring (&url, host, sizeof (host), U_PATH) < 0)
  {
    dprint (1, (debugfile, "bcache_path: URL to string failed\n"));
    return -1;
  }

  mutt_encode_path (path, sizeof (path), NONULL (mailbox));

  len = snprintf (dst, dstlen-1, "%s/%s%s%s", MessageCachedir,
		  host, path,
		  (*path && path[mutt_strlen (path) - 1] == '/') ? "" : "/");

  dprint (3, (debugfile, "bcache_path: rc: %d, path: '%s'\n", len, dst));

  if (len < 0 || len >= dstlen-1)
    return -1;

  dprint (3, (debugfile, "bcache_path: directory: '%s'\n", dst));

  return 0;
}
Example #9
0
header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path)
{
  IMAP_MBOX mx;
  ciss_url_t url;
  char cachepath[LONG_STRING];
  char mbox[LONG_STRING];

  if (path)
    imap_cachepath (idata, path, mbox, sizeof (mbox));
  else
  {
    if (!idata->ctx || imap_parse_path (idata->ctx->path, &mx) < 0)
      return NULL;

    imap_cachepath (idata, mx.mbox, mbox, sizeof (mbox));
    FREE (&mx.mbox);
  }

  mutt_account_tourl (&idata->conn->account, &url);
  url.path = mbox;
  url_ciss_tostring (&url, cachepath, sizeof (cachepath), U_PATH);

  return mutt_hcache_open (HeaderCache, cachepath, imap_hcache_namer);
}
Example #10
0
/* open POP mailbox - fetch only headers */
int pop_open_mailbox(CONTEXT *ctx)
{
    int ret;
    char buf[LONG_STRING];
    CONNECTION *conn;
    ACCOUNT acct;
    POP_DATA *pop_data;
    ciss_url_t url;

    if (pop_parse_path(ctx->path, &acct)) {
        mutt_error(_("%s is an invalid POP path"), ctx->path);
        mutt_sleep(2);
        return -1;
    }

    mutt_account_tourl(&acct, &url);
    url.path = NULL;
    url_ciss_tostring(&url, buf, sizeof(buf), 0);
    conn = mutt_conn_find(NULL, &acct);

    if (!conn)
        return -1;

    safe_free(&ctx->path);
    ctx->path = safe_strdup(buf);

    pop_data = safe_calloc(1, sizeof(POP_DATA));
    pop_data->conn = conn;
    ctx->data = pop_data;
    ctx->mx_close = pop_close_mailbox;

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

    conn->data = pop_data;
    pop_data->bcache = mutt_bcache_open(&acct, NULL);

    /* init (hard-coded) ACL rights */
    memset(ctx->rights, 0, sizeof(ctx->rights));
    mutt_bit_set(ctx->rights, M_ACL_SEEN);
    mutt_bit_set(ctx->rights, M_ACL_DELETE);
    FOREVER
    {
        if (pop_reconnect(ctx) < 0)
            return -1;

        ctx->size = pop_data->size;

        mutt_message _("Fetching list of messages...");

        ret = pop_fetch_headers(ctx);

        if (ret >= 0)
            return 0;

        if (ret < -1) {
            mutt_sleep(2);
            return -1;
        }
    }
}