Пример #1
0
/* given an POP mailbox name, return host, port, username and password */
int pop_parse_path (const char* path, ACCOUNT* acct)
{
  ciss_url_t url;
  char *c;
  struct servent *service;

  /* Defaults */
  acct->flags = 0;
  acct->type = M_ACCT_TYPE_POP;

  c = safe_strdup (path);
  url_parse_ciss (&url, c);

  if ((url.scheme != U_POP && url.scheme != U_POPS) ||
      mutt_account_fromurl (acct, &url) < 0)
  {
    FREE(&c);
    mutt_error(_("Invalid POP URL: %s\n"), path);
    mutt_sleep(1);
    return -1;
  }

  if (url.scheme == U_POPS)
    acct->flags |= M_ACCT_SSL;

  service = getservbyname (url.scheme == U_POP ? "pop3" : "pop3s", "tcp");
  if (service)
    acct->port = ntohs (service->s_port);
  else
    acct->port = url.scheme == U_POP ? POP_PORT : POP_SSL_PORT;;

  FREE (&c);
  return 0;
}
Пример #2
0
/* imap_parse_path: given an IMAP mailbox name, return host, port
 *   and a path IMAP servers will recognise.
 * mx.mbox is malloc'd, caller must free it */
int imap_parse_path (const char *path, IMAP_MBOX * mx)
{
  static unsigned short ImapPort = 0;
  static unsigned short ImapsPort = 0;
  struct servent *service;
  ciss_url_t url;
  char *c;

  if (!ImapPort) {
    service = getservbyname ("imap", "tcp");
    if (service)
      ImapPort = ntohs (service->s_port);
    else
      ImapPort = IMAP_PORT;
    debug_print (3, ("Using default IMAP port %d\n", ImapPort));
  }
  if (!ImapsPort) {
    service = getservbyname ("imaps", "tcp");
    if (service)
      ImapsPort = ntohs (service->s_port);
    else
      ImapsPort = IMAP_SSL_PORT;
    debug_print (3, ("Using default IMAPS port %d\n", ImapsPort));
  }

  /* Defaults */
  mx->account.flags = 0;
  mx->account.port = ImapPort;
  mx->account.type = M_ACCT_TYPE_IMAP;

  c = str_dup (path);
  url_parse_ciss (&url, c);

  if (!(url.scheme == U_IMAP || url.scheme == U_IMAPS) ||
      mutt_account_fromurl (&mx->account, &url) < 0 || !*mx->account.host) {
    mem_free (&c);
    return -1;
  }

  mx->mbox = str_dup (url.path);

  if (url.scheme == U_IMAPS)
    mx->account.flags |= M_ACCT_SSL;

  mem_free (&c);

  if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT))
    mx->account.port = ImapsPort;

  return 0;
}
Пример #3
0
static int smtp_fill_account (ACCOUNT* account)
{
        static unsigned short SmtpPort = 0;

        struct servent* service;
        ciss_url_t url;
        char* urlstr;

        account->flags = 0;
        account->port = 0;
        account->type = M_ACCT_TYPE_SMTP;

        urlstr = safe_strdup (SmtpUrl);
        url_parse_ciss (&url, urlstr);
        if ((url.scheme != U_SMTP && url.scheme != U_SMTPS)
        || mutt_account_fromurl (account, &url) < 0) {
                FREE (&urlstr);
                mutt_error (_("Invalid SMTP URL: %s"), SmtpUrl);
                mutt_sleep (1);
                return -1;
        }
        FREE (&urlstr);

        if (url.scheme == U_SMTPS)
                account->flags |= M_ACCT_SSL;

        if (!account->port) {
                if (account->flags & M_ACCT_SSL)
                        account->port = SMTPS_PORT;
                else {
                        if (!SmtpPort) {
                                service = getservbyname ("smtp", "tcp");
                                if (service)
                                        SmtpPort = ntohs (service->s_port);
                                else
                                        SmtpPort = SMTP_PORT;
                                dprint (3, (debugfile, "Using default SMTP port %d\n", SmtpPort));
                        }
                        account->port = SmtpPort;
                }
        }

        return 0;
}
Пример #4
0
static void
unconditional_mailbox(const gchar * path, const gchar * prettyname,
                      LibBalsaMailbox ** box, gchar ** error)
{
    gchar *dup;
    gchar *index;
    char tmp[32] = "/tmp/balsa.XXXXXX";
    ciss_url_t url;
    gboolean ssl = FALSE, is_remote = FALSE;

    if ((*error) != NULL)
        return;

    dup = g_strdup(path);
    index = strrchr(dup, G_DIR_SEPARATOR);

    if (index == NULL) {
        (*error) =
            g_strdup_printf(_
                            ("The pathname \"%s\" must be specified"
                             " canonically -- it must start with a \'/\'."),
                            dup);
        g_free(dup);
        return;
    }

    *index = '\0';           /*Split off the dirs from the file. */

    if (balsa_init_create_to_directory(dup, error)) {
        /*TRUE->error */
        g_free(dup);
        return;
    }

    *index = G_DIR_SEPARATOR;

    url_parse_ciss(&url, dup);

    switch (url.scheme) {
    case U_IMAPS:
        ssl = TRUE;
    case U_IMAP:
        *box = (LibBalsaMailbox *) libbalsa_mailbox_imap_new();
        libbalsa_mailbox_imap_set_path((LibBalsaMailboxImap *) * box,
                                       url.path);
        is_remote = TRUE;
        break;
    case U_POPS:
        ssl = TRUE;
    case U_POP:
        *box = (LibBalsaMailbox *) libbalsa_mailbox_pop3_new();
        is_remote = TRUE;
        break;
    case U_FILE:
        *box =
            (LibBalsaMailbox *) libbalsa_mailbox_local_new(url.path, TRUE);
        break;
    default:
        *box = (LibBalsaMailbox *) libbalsa_mailbox_local_new(path, TRUE);
    }

    if (is_remote) {
        libbalsa_server_set_host(LIBBALSA_MAILBOX_REMOTE_SERVER(*box),
                                 url.host, ssl);
        libbalsa_server_set_username(LIBBALSA_MAILBOX_REMOTE_SERVER(*box),
                                     getenv("USER"));
    }
    g_free(dup);


    if (*box == NULL) {
        if (strcmp("/var/spool/mail/", path)) {
	    /* Don't fail if you can't create the spool mailbox. */
	    close(mkstemp(tmp));
		*box = (LibBalsaMailbox*)libbalsa_mailbox_local_new(tmp, FALSE);
		if (*box) {
			free((*box)->url);
			(*box)->url = g_strdup_printf("file://%s",path);
		}
		unlink(tmp);
	}
    }
    if ( *box == NULL) {
            (*error) =
                g_strdup_printf(_
                                ("The mailbox \"%s\" does not appear to be valid."),
                                path);
        return;
    }

    (*box)->name = g_strdup(gettext(prettyname));

    config_mailbox_add(*box, (char *) prettyname);
    if (box == &balsa_app.outbox)
        (*box)->no_reassemble = TRUE;
}
Пример #5
0
/* imap_parse_path: given an IMAP mailbox name, return host, port
 *   and a path IMAP servers will recognise.
 * mx.mbox is malloc'd, caller must free it */
int imap_parse_path (const char* path, IMAP_MBOX* mx)
{
  static unsigned short ImapPort = 0;
  static unsigned short ImapsPort = 0;
  struct servent* service;
  char tmp[128];
  ciss_url_t url;
  char *c;
  int n;

  if (!ImapPort)
  {
    service = getservbyname ("imap", "tcp");
    if (service)
      ImapPort = ntohs (service->s_port);
    else
      ImapPort = IMAP_PORT;
    dprint (3, (debugfile, "Using default IMAP port %d\n", ImapPort));
  }
  if (!ImapsPort)
  {
    service = getservbyname ("imaps", "tcp");
    if (service)
      ImapsPort = ntohs (service->s_port);
    else
      ImapsPort = IMAP_SSL_PORT;
    dprint (3, (debugfile, "Using default IMAPS port %d\n", ImapsPort));
  }

  /* Defaults */
  memset(&mx->account, 0, sizeof(mx->account));
  mx->account.port = ImapPort;
  mx->account.type = M_ACCT_TYPE_IMAP;

  c = safe_strdup (path);
  url_parse_ciss (&url, c);
  if (url.scheme == U_IMAP || url.scheme == U_IMAPS)
  {
    if (mutt_account_fromurl (&mx->account, &url) < 0 || !*mx->account.host)
    {
      FREE (&c);
      return -1;
    }

    mx->mbox = safe_strdup (url.path);

    if (url.scheme == U_IMAPS)
      mx->account.flags |= M_ACCT_SSL;

    FREE (&c);
  }
  /* old PINE-compatibility code */
  else
  {
    FREE (&c);
    if (sscanf (path, "{%127[^}]}", tmp) != 1)
      return -1;

    c = strchr (path, '}');
    if (!c)
      return -1;
    else
      /* walk past closing '}' */
      mx->mbox = safe_strdup (c+1);

    if ((c = strrchr (tmp, '@')))
    {
      *c = '\0';
      strfcpy (mx->account.user, tmp, sizeof (mx->account.user));
      strfcpy (tmp, c+1, sizeof (tmp));
      mx->account.flags |= M_ACCT_USER;
    }

    if ((n = sscanf (tmp, "%127[^:/]%127s", mx->account.host, tmp)) < 1)
    {
      dprint (1, (debugfile, "imap_parse_path: NULL host in %s\n", path));
      FREE (&mx->mbox);
      return -1;
    }

    if (n > 1) {
      if (sscanf (tmp, ":%hu%127s", &(mx->account.port), tmp) >= 1)
	mx->account.flags |= M_ACCT_PORT;
      if (sscanf (tmp, "/%s", tmp) == 1)
      {
	if (!ascii_strncmp (tmp, "ssl", 3))
	  mx->account.flags |= M_ACCT_SSL;
	else
	{
	  dprint (1, (debugfile, "imap_parse_path: Unknown connection type in %s\n", path));
	  FREE (&mx->mbox);
	  return -1;
	}
      }
    }
  }

  if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT))
    mx->account.port = ImapsPort;

  return 0;
}