bool mail_connect_imap(mail_account* a, va_list args) { char *host, *user, *pw; uint16_t port; int result; host = va_arg(args, char*); port = (uint16_t) va_arg(args, uint); user = va_arg(args, char*); pw = va_arg(args, char*); result = mailimap_ssl_connect(a->self.imap, host, port); switch (result) { case MAILIMAP_NO_ERROR: case MAILIMAP_NO_ERROR_AUTHENTICATED: case MAILIMAP_NO_ERROR_NON_AUTHENTICATED: break; default: /* TODO handle other return values */ return false; } result = mailimap_login(a->self.imap, user, pw); switch (result) { case MAILIMAP_NO_ERROR: case MAILIMAP_NO_ERROR_AUTHENTICATED: case MAILIMAP_NO_ERROR_NON_AUTHENTICATED: return true; default: /* TODO handle other return values */ return false; } }
int main(int argc, char ** argv) { struct mailimap * imap; int r; /* ./imap-sample [email protected] mygmailpassword */ if (argc < 3) { fprintf(stderr, "usage: imap-sample [gmail-email-address] [password]\n"); exit(EXIT_FAILURE); } mkdir("download", 0700); imap = mailimap_new(0, NULL); r = mailimap_ssl_connect(imap, "imap.gmail.com", 993); fprintf(stderr, "connect: %i\n", r); check_error(r, "could not connect to server"); r = mailimap_login(imap, argv[1], argv[2]); check_error(r, "could not login"); r = mailimap_select(imap, "INBOX"); check_error(r, "could not select INBOX"); fetch_messages(imap); mailimap_logout(imap); mailimap_free(imap); exit(EXIT_SUCCESS); }