summaryrefslogtreecommitdiffabout
path: root/kmicromail/libetpan/pop3
Side-by-side diff
Diffstat (limited to 'kmicromail/libetpan/pop3') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/pop3/mailpop3.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/kmicromail/libetpan/pop3/mailpop3.c b/kmicromail/libetpan/pop3/mailpop3.c
index 28fafe9..691b07a 100644
--- a/kmicromail/libetpan/pop3/mailpop3.c
+++ b/kmicromail/libetpan/pop3/mailpop3.c
@@ -383,258 +383,261 @@ int mailpop3_quit(mailpop3 * f)
int mailpop3_apop(mailpop3 * f,
const char * user, const char * password)
{
char command[POP3_STRING_SIZE];
MD5_CTX md5context;
unsigned char md5digest[16];
char md5string[33];
char * cmd_ptr;
int r;
int i;
char * response;
if (f->pop3_state != POP3_STATE_AUTHORIZATION)
return MAILPOP3_ERROR_BAD_STATE;
if (f->pop3_timestamp == NULL)
return MAILPOP3_ERROR_APOP_NOT_SUPPORTED;
/* calculate md5 sum */
MD5Init(&md5context);
MD5Update(&md5context, f->pop3_timestamp, strlen (f->pop3_timestamp));
MD5Update(&md5context, password, strlen (password));
MD5Final(md5digest, &md5context);
cmd_ptr = md5string;
for(i = 0 ; i < 16 ; i++, cmd_ptr += 2)
snprintf(cmd_ptr, 3, "%02x", md5digest[i]);
* cmd_ptr = 0;
/* send apop command */
snprintf(command, POP3_STRING_SIZE, "APOP %s %s\r\n", user, md5string);
r = send_command(f, command);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
r = parse_response(f, response);
if (r != RESPONSE_OK)
return MAILPOP3_ERROR_DENIED;
f->pop3_state = POP3_STATE_TRANSACTION;
return MAILPOP3_NO_ERROR;
}
int mailpop3_user(mailpop3 * f, const char * user)
{
char command[POP3_STRING_SIZE];
int r;
char * response;
if (f->pop3_state != POP3_STATE_AUTHORIZATION)
return MAILPOP3_ERROR_BAD_STATE;
/* send user command */
snprintf(command, POP3_STRING_SIZE, "USER %s\r\n", user);
r = send_command(f, command);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
r = parse_response(f, response);
if (r != RESPONSE_OK)
return MAILPOP3_ERROR_BAD_USER;
return MAILPOP3_NO_ERROR;
}
int mailpop3_pass(mailpop3 * f, const char * password)
{
char command[POP3_STRING_SIZE];
int r;
char * response;
if (f->pop3_state != POP3_STATE_AUTHORIZATION)
return MAILPOP3_ERROR_BAD_STATE;
/* send password command */
snprintf(command, POP3_STRING_SIZE, "PASS %s\r\n", password);
r = send_command(f, command);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
r = parse_response(f, response);
- if (r != RESPONSE_OK)
+ if (r != RESPONSE_OK) {
+ // LR
+ fprintf(stderr,"POP3 login error. Response from server:\n%s\n",response );
return MAILPOP3_ERROR_BAD_PASSWORD;
+ }
f->pop3_state = POP3_STATE_TRANSACTION;
return MAILPOP3_NO_ERROR;
}
static int read_list(mailpop3 * f, carray ** result);
static int read_uidl(mailpop3 * f, carray * msg_tab);
static int mailpop3_do_uidl(mailpop3 * f, carray * msg_tab)
{
char command[POP3_STRING_SIZE];
int r;
char * response;
if (f->pop3_state != POP3_STATE_TRANSACTION)
return MAILPOP3_ERROR_BAD_STATE;
/* send list command */
snprintf(command, POP3_STRING_SIZE, "UIDL\r\n");
r = send_command(f, command);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
r = parse_response(f, response);
if (r != RESPONSE_OK)
return MAILPOP3_ERROR_CANT_LIST;
r = read_uidl(f, msg_tab);
if (r != MAILPOP3_NO_ERROR)
return r;
return MAILPOP3_NO_ERROR;
}
static int mailpop3_do_list(mailpop3 * f)
{
char command[POP3_STRING_SIZE];
int r;
carray * msg_tab;
char * response;
if (f->pop3_msg_tab != NULL) {
mailpop3_msg_info_tab_free(f->pop3_msg_tab);
f->pop3_msg_tab = NULL;
}
if (f->pop3_state != POP3_STATE_TRANSACTION)
return MAILPOP3_ERROR_BAD_STATE;
/* send list command */
snprintf(command, POP3_STRING_SIZE, "LIST\r\n");
r = send_command(f, command);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
r = parse_response(f, response);
if (r != RESPONSE_OK)
return MAILPOP3_ERROR_CANT_LIST;
r = read_list(f, &msg_tab);
if (r != MAILPOP3_NO_ERROR)
return r;
f->pop3_msg_tab = msg_tab;
f->pop3_deleted_count = 0;
mailpop3_do_uidl(f, msg_tab);
return MAILPOP3_NO_ERROR;
}
static void mailpop3_list_if_needed(mailpop3 * f)
{
if (f->pop3_msg_tab == NULL)
mailpop3_do_list(f);
}
/*
mailpop3_list
*/
void mailpop3_list(mailpop3 * f, carray ** result)
{
mailpop3_list_if_needed(f);
* result = f->pop3_msg_tab;
}
static inline struct mailpop3_msg_info *
find_msg(mailpop3 * f, unsigned int index)
{
mailpop3_list_if_needed(f);
if (f->pop3_msg_tab == NULL)
return NULL;
return mailpop3_msg_info_tab_find_msg(f->pop3_msg_tab, index);
}
static void mailpop3_multiline_response_free(char * str)
{
mmap_string_unref(str);