[go: up one dir, main page]

Menu

[r64]: / trunk / man / libmail_pop3.3  Maximize  Restore  History

Download this file

207 lines (200 with data), 6.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
.\" This file is part of libmail.
.\"
.\" (c) 2009 - Dimitris Mandalidis <mandas@users.sourceforge.net>
.\"
.\" libmail is free software: you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation, either version 3 of the License, or
.\" (at your option) any later version.
.\"
.\" libmail is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with libmail. If not, see <http://www.gnu.org/licenses/>.
.TH LIBMAIL_POP3 3 "2009-06-08" "version 0.3" "libmail - A mail handling library"
.SH NAME
pop3_check, pop3_authenticate, pop3_disconnect, pop3_connect - libmail's
POP3 protocol supporting functions
.SH SYNOPSIS
.nf
.B #include <libmail/libmail.h>
.B #include <libmail/pop3.h>
.sp
.BI "int pop3_connect(pop3_mailbox_t *" "server" );
.sp
.BI "int pop3_disconnect(pop3_mailbox_t *" "server" );
.sp
.BI "int pop3_authenticate(pop3_mailbox_t *" "server" );
.sp
.BI "int pop3_check(pop3_mailbox_t *" "server" ", int *" "n_new_messages" ", int *" "n_messages" );
.fi
.SH DESCRIPTION
All the above functions takes a pointer to
.B pop3_mailbox_t
structure which identify the server's configuration. More specifically
.I pop3_mailbox_t
is defined as follows :
.sp
.nf
typedef struct libmail_remote_server_t {
char hostname[HOST_NAME_MAX+1];
char port[6];
short inet_family;
short use_secure;
int sfd;
} libmail_remote_server_t;
typedef struct pop3_mailbox_t {
libmail_remote_server_t server;
libmail_auth_t auth;
char greeting[BUFSIZE+1];
} pop3_mailbox_t;
.fi
.sp
The server's hostname and port are specified in
.I hostname
and
.I port
respectively while
.I inet_family
might be
.BR "LIBMAIL_IPV4" " or " "LIBMAIL_IPV6"
to indicate IP protocol version.
.I use_secure
might be
.BR "LIBMAIL_USE_SECURE" " or " "LIBMAIL_USE_PLAIN"
to indicate if the session will be encrypted (if compiled with --enable-tls)
.I sfd
contains the socket file descriptor as returned by
.B pop3_connect()
(see below).
.I greeting
is the server's initial response which might be used for the APOP login
method.
.I auth
is a
.B libmail_auth_t
structure which is defined as follows :
.sp
.nf
typedef struct libmail_auth_t {
char username[BUFSIZE+1];
char password[BUFSIZE+1];
short auth_type;
} libmail_auth_t;
.fi
.sp
.I username
and
.I password
contain the login credentials for the server and
.I auth_type
can be
.B AUTH_POP3_USERPASS
for a USER/PASS login method,
.B AUTH_POP3_APOP
for the APOP login method (if compiled with --enable-apop) and
.B AUTH_POP3_SASL
for using a supported SASL authentication mechanism (if compile with --enable-sasl).
.sp
Although the function names are self-descriptive here is a short
description;
.B pop3_connect()
is used for the initial connection to the server, assigning a valid socket
file descriptor to
.IR server->sfd .
.B pop3_authenticate()
authenticates the user based on the info provided by
.IR server->auth .
.B pop3_check()
checks for messages filling the
.I n_messages
and
.I n_new_messages
with the number of total and new messages respectively.
.B pop3_disconnect()
disconnects the user from the server.
.SH "RETURN VALUE"
All four functions return
.B LIBMAIL_SUCCESS
if they succeed. On error they return the following non-zero error codes :
.TP
.B LIBMAIL_SYSERROR
A system error occurred, errno defined in <errno.h> was set. Returned by
all four functions.
.TP
.B LIBMAIL_DNSERROR
The hostname specified in
.I server
was invalid resulting in "unresolved hostname"\-like error. Returned only by
.B pop3_connect().
.TP
.B LIBMAIL_SRVERROR
Returned by all. Indicates that the server responded with an "-ERR" to a
command.
.TP
.B LIBMAIL_POP3_UNSUPPORTED_APOP
Return by pop3_authenticate() when APOP authentication is requested by the
user side and the server doesn't support it.
.TP
.B LIBMAIL_POP3_INVALID_USER
Return by pop3_authenticate() when the supplied username is incorrect.
.B LIBMAIL_POP3_INVALID_PASSWORD
Return by pop3_authenticate() when the supplied password is incorrect.
.B LIBMAIL_POP3_MD5_ERROR
Return by pop3_authenticate() when the supplied MD5 digest to APOP
authentication mechanism is incorrect.
.B LIBMAIL_TLSERROR
Returned by all function indicating an error in TLS/SSL transaction context.
You can retrieve a short description about a specific error through libmail_strerror()
.SH "SEE ALSO"
.B RFC 1321, RFC 1939, RFC 2222, RFC 2822, RFC 4346
.BR "libmail_strerror" "(3)"
.SH "BUGS"
Currently a real check for unread messages isn't implemented,
n_new_messages is always equal to n_messages after the call to
pop3_check().
.SH "AUTHOR"
Dimitris Mandalidis <mandas AT users DOT sourceforge DOT net>
.SH "EXAMPLES"
A short example on using libmail POP3 protocol support follows:
.sp
.nf
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libmail/libmail.h>
#include <libmail/pop3.h>
#include <libmail/error.h>
void pop3_test(void) {
pop3_mailbox_t mailbox;
int result;
int n_new_messages, n_messages;
strcpy(mailbox.server.hostname, "localhost");
strcpy(mailbox.server.port, "110");
mailbox.server.inet_family = LIBMAIL_IPV4;
strcpy(mailbox.auth.username, "mailtest");
strcpy(mailbox.auth.password, "foo");
mailbox.auth.auth_type = AUTH_POP3_SASL;
if ((result = pop3_connect(&mailbox)) != 0) {
printf("ERROR: %s", libmail_strerror(result));
exit(EXIT_FAILURE);
}
if ((result = pop3_authenticate(&mailbox)) != 0) {
printf("ERROR: %s", libmail_strerror(result));
exit(EXIT_FAILURE);
}
if ((result = pop3_check(&mailbox, &n_new_messages, &n_messages)) != 0) {
printf("ERROR: %s", libmail_strerror(result));
exit(EXIT_FAILURE);
}
if ((result = pop3_disconnect(&mailbox)) != 0) {
printf("ERROR: %s", libmail_strerror(result));
exit(EXIT_FAILURE);
}
printf("%d total messages and %d new messages", n_messages, n_new_messages);
return;
}
.fi