libspopc.h | libspopc.h | |||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
#ifndef _LIBSPOPC_H | #ifndef _LIBSPOPC_H | |||
#define _LIBSPOPC_H | #define _LIBSPOPC_H | |||
#include <sys/socket.h> | #include <sys/socket.h> | |||
#include <sys/types.h> | #include <sys/types.h> | |||
#include <netinet/in.h> | #include <netinet/in.h> | |||
#include <netdb.h> | #include <netdb.h> | |||
/*************************************** | /*************************************** | |||
* low-level methods for a pop3 client * | * low-level methods for a pop3 client * | |||
***************************************/ | ***************************************/ | |||
/************************************************************************** | ||||
**** | ||||
* Be careful, using the low-level API is uncompliant with using the high | ||||
* | ||||
* level API. Here, you make your choice. If you don't know the pop3 protoc | ||||
ol * | ||||
* or what a socket is, it is then warmly recommended to use the *high-leve | ||||
l* * | ||||
* API if which is shown far below on this file. | ||||
* | ||||
************************************************************************** | ||||
****/ | ||||
/************** | /************** | |||
* connecting * | * connecting * | |||
**************/ | **************/ | |||
int pop3_prepare(const char* servername, const int port, struct sockaddr_in * connection, struct hostent* server); | int pop3_prepare(const char* servername, const int port, struct sockaddr_in * connection, struct hostent* server); | |||
/* prepares the pop session and returns a socket descriptor */ | /* prepares the pop session and returns a socket descriptor */ | |||
char* pop3_connect(int sock, struct sockaddr_in* connection); | char* pop3_connect(int sock, struct sockaddr_in* connection); | |||
/* connects to the server through the sock and returns server's welcome */ | /* connects to the server through the sock and returns server's welcome */ | |||
void pop3_disconnect(int sock); | void pop3_disconnect(int sock); | |||
/* close socket */ | /* close socket */ | |||
/**************** | /**************** | |||
* pop3 queries * | * pop3 queries * | |||
****************/ | ****************/ | |||
char* pop3_user(int sock, char* name); | char* pop3_user(int sock, char* name); | |||
/* performs "USER" pop query and returns server's <64 bytes response */ | /* performs "USER" pop query and returns server's <128 bytes response */ | |||
char* pop3_pass(int sock, char* pw); | char* pop3_pass(int sock, char* pw); | |||
/* performs "PASS" pop query and return server's <63 bytes response */ | /* performs "PASS" pop query and return server's <128 bytes response */ | |||
char* pop3_quit(int sock); | char* pop3_quit(int sock); | |||
/* performs "QUIT" pop query and returns server's <64 bytes response */ | /* performs "QUIT" pop query and returns server's <128 bytes response */ | |||
char* pop3_stat(int sock); | char* pop3_stat(int sock); | |||
/* performs "STAT" pop query and returns server's <64 bytes response */ | /* performs "STAT" pop query and returns server's <128 bytes response */ | |||
char* recv_rest(int sock, char* buf, int cs, int bs); | ||||
/* recv rest of data through sock, given a cs bytes filled buffer of total | ||||
size bs */ | ||||
/* end of data is assumed when data has a "\n.\n" or "\n.\0" string */ | ||||
char* pop3_list(int sock, int id); | char* pop3_list(int sock, int id); | |||
/* performs a "LIST" pop query and returns server's (long) response */ | /* performs a "LIST" pop query and returns server's (long) response */ | |||
char* pop3_retr(int sock, int id); | char* pop3_retr(int sock, int id); | |||
/* performs a "RETR" pop query and returns server's (long) response */ | /* performs a "RETR" pop query and returns server's (long) response */ | |||
char* pop3_dele(int sock, int id); | char* pop3_dele(int sock, int id); | |||
/* performs a "DELE" pop query and returns server's <64 bytes response */ | /* performs a "DELE" pop query and returns server's <128 bytes response */ | |||
char* pop3_noop(int sock); | char* pop3_noop(int sock); | |||
/* performs a "NOOP" pop query and returns server's <64 bytes response */ | /* performs a "NOOP" pop query and returns server's <128 bytes response */ | |||
char* pop3_rset(int sock); | char* pop3_rset(int sock); | |||
/* performs a "RSET" pop query and returns server's <64 bytes response */ | /* performs a "RSET" pop query and returns server's <128 bytes response */ | |||
char* pop3_top(int sock, int id, int lines); | char* pop3_top(int sock, int id, int lines); | |||
/* performs a "TOP" pop query and returns server's (long) response */ | /* performs a "TOP" pop query and returns server's (long) response */ | |||
char* pop3_uidl(int sock, int id); | char* pop3_uidl(int sock, int id); | |||
/* performs a "UIDL" pop query and returns server's (long) response */ | /* performs a "UIDL" pop query and returns server's (long) response */ | |||
char* pop3_apop(int sock, char* name, char* digest); | char* pop3_apop(int sock, char* name, char* digest); | |||
/* performs a "APOP" secure pop query and returns server's <64 bytes respon | /* performs a "APOP" secure pop query and returns server's <128 bytes respo | |||
se */ | nse */ | |||
/* this one is not in the API, just for libspopc internal use: */ | ||||
char* recv_rest(int sock, char* buf, int cs, int bs); | ||||
/* recv rest of data through sock, given a cs bytes filled buffer of total | ||||
size bs */ | ||||
/* end of data is assumed when data has a "\n.\n" or "\n.\0" string */ | ||||
/********************* | /********************* | |||
* parsing utilities * | * parsing utilities * | |||
*********************/ | *********************/ | |||
#define DOTLINE(s) (((s)[0]=='\r'||(s)[0]=='\n')&&((s)[1]=='.')&&((s)[2]==' \r'||(s)[2]=='\n'||(s)[2]=='\0')) /* be careful, it's different to ESR's po p3.c ;-) */ | #define DOTLINE(s) (((s)[0]=='\r'||(s)[0]=='\n')&&((s)[1]=='.')&&((s)[2]==' \r'||(s)[2]=='\n'||(s)[2]=='\0')) /* be careful, it's different to ESR's po p3.c ;-) */ | |||
#define DOTBEGIN(s) (((s)[0]=='\r'||(s)[0]=='\n')&&((s)[1]=='.')) | #define DOTBEGIN(s) (((s)[0]=='\r'||(s)[0]=='\n')&&((s)[1]=='.')) | |||
int dotline(char* buf, int bs); | int dotline(char* buf, int bs); | |||
/* returns 1 if buf contains a "\n.\n" or "\n.\0" substring */ | /* returns 1 if buf contains a "\n.\n" or "\n.\0" or \r.(etc) substring */ | |||
int pop3_error(char* string); | int pop3_error(char* string); | |||
/* returns 1 if pop server error reply (i.e : -ERR ...) */ | /* returns 1 if pop server error reply (i.e : -ERR ...) */ | |||
/********************************** | /************************************ | |||
* formatting methods, post query * | * reply re-formatting, after query * | |||
**********************************/ | ************************************/ | |||
char* nextline(char* string); | char* nextline(char* string); | |||
/* returns a pointer to the next line of given string */ | /* returns a pointer to the next line of given string */ | |||
char* retr2msg(char* data); | char* retr2msg(char* data); | |||
/* retruns formatted mail from a pop RETR X query */ | /* returns formatted mail from a pop RETR X query */ | |||
/* should only be called on data returned by pop3_retr() */ | /* must only be called on data returned by pop3_retr() */ | |||
int* list2array(char* poplist); | int* list2array(char* poplist); | |||
/* returns an int array of sizes of messages from a LIST pop query */ | /* returns an int array of sizes of messages from a LIST pop query */ | |||
/* array[0] holds id of the array's element */ | /* array[0] holds id of the array's last element */ | |||
/* should only be called on data received by a pop3_list() request */ | /* must only be called on data received by a pop3_list(sock,0) request */ | |||
int listi2size(char* resp); | ||||
/* grep the given size (in bytes) in resp after a pop3_list(sock,ID) reques | ||||
t */ | ||||
int stat2last(char* resp); | ||||
/* returns the number of stored messages on pop server */ | ||||
int stat2bytes(char* resp); | ||||
/* returns the sumsize in bytes of all stored messages on server */ | ||||
/* should only be called just after a pop3_stat() request */ | ||||
char** uidl2array(char* resp); | ||||
/* returns an array of unique strings for each message id */ | ||||
/* array[0] gives array's last id */ | ||||
/* should only be called just after a pop3_uidl() request */ | ||||
char* uidli2sig(char* resp); | ||||
/* array[0] holds id of the array's element */ | ||||
/* should only be called on data received by a pop3_list() request */ | ||||
int listi2size(char* resp); | int listi2size(char* resp); | |||
/* grep the given size (in bytes) in resp after a pop3_list(sock,ID) reques t */ | /* grep the given size (in bytes) in resp after a pop3_list(sock,ID) reques t */ | |||
/* do not use after a pop3_list(sock,0) ! */ | ||||
int stat2last(char* resp); | int stat2last(char* resp); | |||
/* returns the number of stored messages on pop server */ | /* returns the number of stored messages on pop server */ | |||
int stat2bytes(char* resp); | int stat2bytes(char* resp); | |||
/* returns the sumsize in bytes of all stored messages on server */ | /* returns the sumsize in bytes of all stored messages on server */ | |||
/* should only be called just after a pop3_stat() request */ | /* must only be called just after a pop3_stat() request */ | |||
char** uidl2array(char* resp); | char** uidl2array(char* resp); | |||
/* returns an array of unique strings for each message id */ | /* returns an array of unique strings for each message id */ | |||
/* array[0] gives array's last id */ | /* array[0] gives array's last id */ | |||
/* should only be called just after a pop3_uidl() request */ | /* must only be called just after a pop3_uidl(sock,0) request */ | |||
char* uidli2sig(char* resp); | char* uidli2sig(char* resp); | |||
/* greps signature from server resp */ | /* grep the pop signature of *one* message signature reply*/ | |||
/* should only be called after a pop3_uidl(sock,ID) */ | /* should only be called on data received by a pop3_uidl(sock,ID) request * | |||
/ | ||||
/* do not use it after a pop3_uidl(sock,0) ! */ | ||||
/*************************************************** | /*************************************************** | |||
* high-level objects and methods for a SIMPLE MDA * | * high-level API for a SIMPLE MDA/MUA * | |||
***************************************************/ | ***************************************************/ | |||
/************************************************************************** | ||||
**** | ||||
* This is the high-level API of libspopc and it is recommended to use it | ||||
* | ||||
* instead of the low-level one. This high-level API, in spite of its very | ||||
* | ||||
* 'teasing' name, just provides a *very simple* way to access and query a | ||||
* | ||||
* pop3 server with your e-mail client. This API handles pop3 in a very | ||||
* | ||||
* convenient manner for the non 'socket-aware' C developper. | ||||
* | ||||
************************************************************************** | ||||
****/ | ||||
typedef enum{AUTHORIZATION,TRANSACTION,UPDATE}popstate; | typedef enum{AUTHORIZATION,TRANSACTION,UPDATE}popstate; | |||
/* pop server states definition from RFC 1725*/ | /* pop server states definition from RFC 1725*/ | |||
typedef struct{ | typedef struct{ | |||
int sock;/* socket descriptor */ | int sock;/* socket descriptor */ | |||
struct sockaddr_in* connection; | struct sockaddr_in* connection; | |||
struct hostent* server; | struct hostent* server; | |||
popstate state;/* pop server state */ | popstate state;/* pop server state */ | |||
int* list;/* pop messages size list */ | int* list;/* pop messages size list */ | |||
char** uidl;/* pop messages signature list */ | char** uidl;/* pop messages signature list */ | |||
int bytes;/* total stored (in bytes) on pop server */ | int bytes;/* total stored (in bytes) on pop server */ | |||
int last;/* last message id */ | int last;/* last message id */ | |||
int del;/* 0|1 flag to ask deletion of retrieved messages */ | int del;/* 0|1 flag to ask deletion of retrieved messages */ | |||
}popsession; | }popsession; | |||
#define popbytes(s) ((s)->bytes) | #define popbytes(s) ((s)->bytes) | |||
/* gives the total stored data size (in bytes) on the pop server */ | /* gives the total stored data size (in bytes) on the pop server */ | |||
/* arg is type 'popsession*'; return is type 'int' */ | /* arg 's' is type 'popsession*'; 'result' is type 'int' */ | |||
#define popnum(s) ((s)->last) | #define popnum(s) ((s)->last) | |||
/* gives the number of messages stored on the pop server before any operati on */ | /* gives the number of messages stored on the pop server before any operati on */ | |||
/* arg is type 'popsession*'; return is type 'int' */ | /* arg 's' is type 'popsession*'; 'result' is type 'int' */ | |||
#define popsetdel(s) ((s)->del=1) | #define popsetdel(s) ((s)->del=1) | |||
/* asks the session to delete any retrieved messages on the server */ | /* asks the session to delete any retrieved messages on the server */ | |||
/* arg is type 'popsession*' */ | /* arg 's' is type 'popsession*' */ | |||
#define popsetundel(s) ((s)->del=0) | #define popsetundel(s) ((s)->del=0) | |||
/* asks the session to not delete any retrieved message on the server */ | /* asks the session to not delete any retrieved message on the server */ | |||
/* arg 's' is type 'popsession*' */ | /* arg 's' is type 'popsession*' */ | |||
#define popmsgsize(s,i) ((s)->list[(i)]) | #define popmsgsize(s,i) ((s)->list[(i)]) | |||
/* gives the size of message 'i' for session 's' */ | /* gives the size of message 'i' for session 's' */ | |||
/* args are type 'session*'(s) and 'int'(i) */ | /* args are type 'session*'(s) and 'int'(i) */ | |||
/* i must not be 0 */ | /* 'i' must *not* be 0 */ | |||
#define popmsguid(s,i) ((s)->uidl[(i)]) | #define popmsguid(s,i) ((s)->uidl[(i)]) | |||
/* gives the 'char*' uid (unique signature) of 'int' message id */ | /* points to the 'char*' uid (unique signature) of 'int'(i) message id */ | |||
char* popbegin(char* servername,char* user,char* pass, popsession** sp); | char* popbegin(char* servername,char* user,char* pass, popsession** sp); | |||
/* prepares, connect and get lists of messages stored on pop server */ | /* prepares, connect and get lists of messages stored on pop server */ | |||
/* you must give a valid servername, user and pass */ | /* you must give a valid servername, user and pass */ | |||
/* returns an error message if a problem occurs, else NULL */ | /* returns an error message if a problem occurs, else NULL */ | |||
char* popgethead(popsession* session, int id); | char* popgethead(popsession* session, int id); | |||
/* returns the header of a message (id from 1 to popnum()) or NULL if bad i d */ | /* returns the header of a message (id from 1 to popnum()) or NULL if bad i d */ | |||
char* popgetmsg(popsession* session, int id); | char* popgetmsg(popsession* session, int id); | |||
End of changes. 24 change blocks. | ||||
52 lines changed or deleted | 65 lines changed or added | |||