6 /* Contains default for connections */
7 #include "pop3_config.h"
12 void usage(const char *appname
)
14 fprintf(stderr
, "Usage:\n%s [parameters]\n", appname
);
15 fprintf(stderr
, "Parameters:\n");
16 fprintf(stderr
, " -h <host> Server Hostname or IP address\n"
17 " -p <port> Server Port\n"
18 " -u <user> Username\n"
19 " -P <password> Password\n"
20 " -s Use SSL connection\n"
21 " -r RETR command instead TOP\n");
24 int main(int argc
, char **argv
)
29 char *hostname
= NULL
;
34 unsigned int authentication_type
= POP3_AUTH_USERPASS
;
36 /* POP3 Command used to test */
37 unsigned int pop3_command
= CMD_TOP
;
39 struct pop3_mailbox mb
;
42 while ((opt
= getopt(argc
, argv
, "u:h:p:P:sr")) != -1) {
54 pop3_command
= CMD_RETR
;
57 authentication_type
= POP3_AUTH_SSL
;
63 fprintf(stderr
, "Unknown parameter.\n");
70 if (authentication_type
!= POP3_AUTH_SSL
)
71 hostname
= POP3_DEFAULT_HOST
;
73 hostname
= POP3_SSL_DEFAULT_HOST
;
77 if (authentication_type
!= POP3_AUTH_SSL
)
78 port
= POP3_DEFAULT_PORT
;
80 port
= POP3_SSL_DEFAULT_PORT
;
84 if (authentication_type
!= POP3_AUTH_SSL
)
85 user
= POP3_DEFAULT_USER
;
87 user
= POP3_SSL_DEFAULT_USER
;
91 if (authentication_type
!= POP3_AUTH_SSL
)
92 pass
= POP3_SSL_DEFAULT_PASSWORD
;
94 pass
= POP3_DEFAULT_PASSWORD
;
97 mb
.host
.name
= hostname
;
100 mb
.auth
.type
= authentication_type
;
105 fprintf(stderr
, "Connecting %s to %s:%s...\n", user
, hostname
, port
);
107 if (pop3_connect(&mb
) < 0) {
108 fprintf(stderr
, "Connect error\n");
112 if (pop3_authenticate(&mb
) < 0) {
116 /* Retrieve the server capabilities */
118 if (pop3_capa(&mb
) < 0) {
123 /* Retrieve the number of messages present on the mailbox */
124 if (pop3_stat(&mb
) < 0) {
128 fprintf(stderr
, "%u Message in maildrop\n", mb
.messages
);
130 /* Retrieve the message list */
131 if (mb
.messages
> 0) {
136 for (n
= 1; n
<= mb
.messages
; n
++) {
137 if (CMD_RETR
== pop3_command
) {
138 rc
= pop3_retr(&mb
, n
);
140 rc
= pop3_top(&mb
, n
);
143 fprintf(stderr
, "%s - ERROR n=%u\n", __func__
, n
);
150 pop3_disconnect(&mb
);