Example #1
0
void try_imap4(void)
{
	char user_account[80];

	imap_connect( "", 0 );	/* connect to default server */
	if (imapi) {		/* connection successful? */
		imap_capability();
		if (get_password_dialog( user_password )) {
		/*	show_status( ErrMsg(EM_LogonValidate) ); */
			strcpy( user_account, prefs.account_name );
			if (user_account[0]=='\0') {
				strcpy( user_account, prefs.email_address );
				strtok( user_account, "@" );
			}
			imap_login( user_account, user_password );
			imap_select( "INBOX" );
			imap_noop();
			imap_logout();
			while (imap_deque_unsolicited( header, (int)sizeof(header) );
		}
	}
}
Example #2
0
/*
 * Connect to the server, login to the IMAP server, get it's capabilities, get
 * the namespace of the mailboxes.
 */
int
request_login(const char *server, const char *port, const char *ssl,
    const char *user, const char *pass)
{
	int r = -1, rg = -1;
	session *s;

	if ((s = session_find(server, port, user)))
		return STATUS_RESPONSE_NONE;

	s = session_new();

	s->server = xstrdup(server);
	s->port = xstrdup(port);
	s->username = xstrdup(user);

	if (ssl && strncasecmp(ssl, "tls1", 4) &&
	    strncasecmp(ssl, "ssl3", 4) && strncasecmp(ssl, "ssl2", 4))
		ssl = NULL;

	if (open_connection(s, server, port, ssl) == -1)
		goto fail;

	if ((rg = response_greeting(s)) == -1)
		goto fail;

	if (opts.debug)
		if (response_generic(s, imap_noop(s)) == -1)
			goto fail;

	if (response_capability(s, imap_capability(s)) == -1)
		goto fail;

#ifndef NO_SSLTLS
	if (!ssl && s->capabilities & CAPABILITY_STARTTLS &&
	    get_option_boolean("starttls"))
		switch (response_generic(s, imap_starttls(s))) {
		case STATUS_RESPONSE_OK:
			if (open_secure_connection(s, server, port, "tls1")
			    == -1)
				goto fail;
			if (response_capability(s, imap_capability(s)) == -1)
				goto fail;
			break;
		case -1:
			goto fail;
			break;
		}
#endif

	if (rg != STATUS_RESPONSE_PREAUTH) {
#ifndef NO_CRAMMD5
		if (s->capabilities & CAPABILITY_CRAMMD5 &&
		    get_option_boolean("crammd5")) {
			if ((r = auth_cram_md5(s, user, pass)) == -1)
				goto fail;
		}
#endif
		if (r != STATUS_RESPONSE_OK &&
		    (r = response_generic(s, imap_login(s, user, pass))) == -1)
			goto fail;

		if (r == STATUS_RESPONSE_NO) {
			error("username %s or password rejected at %s\n",
			    user, server);
			goto fail;
		}
	} else {
		r = STATUS_RESPONSE_PREAUTH;
	}

	if (response_capability(s, imap_capability(s)) == -1)
		goto fail;

	if (s->capabilities & CAPABILITY_NAMESPACE &&
	    get_option_boolean("namespace")) {
		if (response_namespace(s, imap_namespace(s)) == -1)
			goto fail;
	}

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}