mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-26 08:40:12 +01:00
got rid of ipv4 specific code from imap/pop3 importing
This commit is contained in:
parent
68882e0f47
commit
4e922152d6
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#define VERSION "0.1.23-master-branch"
|
#define VERSION "0.1.23-master-branch"
|
||||||
|
|
||||||
#define BUILD 783
|
#define BUILD 784
|
||||||
|
|
||||||
#define HOSTID "mailarchiver"
|
#define HOSTID "mailarchiver"
|
||||||
|
|
||||||
|
17
src/imap.c
17
src/imap.c
@ -191,28 +191,13 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int connect_to_imap_server(int sd, int *seq, char *server, char *username, char *password, int port, struct __data *data, int use_ssl){
|
int connect_to_imap_server(int sd, int *seq, char *username, char *password, int port, struct __data *data, int use_ssl){
|
||||||
int n;
|
int n;
|
||||||
char tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], buf[MAXBUFSIZE];
|
char tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], buf[MAXBUFSIZE];
|
||||||
unsigned long host=0;
|
|
||||||
struct sockaddr_in remote_addr;
|
|
||||||
X509* server_cert;
|
X509* server_cert;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
|
|
||||||
host = resolve_host(server);
|
|
||||||
|
|
||||||
remote_addr.sin_family = AF_INET;
|
|
||||||
remote_addr.sin_port = htons(port);
|
|
||||||
remote_addr.sin_addr.s_addr = host;
|
|
||||||
bzero(&(remote_addr.sin_zero),8);
|
|
||||||
|
|
||||||
if(connect(sd, (struct sockaddr *)&remote_addr, sizeof(struct sockaddr)) == -1){
|
|
||||||
printf("connect()\n");
|
|
||||||
return ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(use_ssl == 1){
|
if(use_ssl == 1){
|
||||||
|
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
|
16
src/misc.c
16
src/misc.c
@ -533,22 +533,6 @@ void strtolower(char *s){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long resolve_host(char *host){
|
|
||||||
struct hostent *h;
|
|
||||||
struct in_addr addr;
|
|
||||||
|
|
||||||
if(!host) return 0;
|
|
||||||
|
|
||||||
if((addr.s_addr = inet_addr(host)) == -1){
|
|
||||||
if((h = gethostbyname(host)) == NULL){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else return *(unsigned long*)h->h_addr;
|
|
||||||
}
|
|
||||||
else return addr.s_addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
char *strcasestr(const char *s, const char *find){
|
char *strcasestr(const char *s, const char *find){
|
||||||
char c, sc;
|
char c, sc;
|
||||||
|
@ -39,8 +39,6 @@ void init_session_data(struct session_data *sdata, struct __config *cfg);
|
|||||||
int read_from_stdin(struct session_data *sdata);
|
int read_from_stdin(struct session_data *sdata);
|
||||||
void strtolower(char *s);
|
void strtolower(char *s);
|
||||||
|
|
||||||
unsigned long resolve_host(char *host);
|
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
char *strcasestr(const char *s, const char *find);
|
char *strcasestr(const char *s, const char *find);
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -31,10 +34,10 @@ int quiet=0;
|
|||||||
int remove_after_successful_import = 0;
|
int remove_after_successful_import = 0;
|
||||||
|
|
||||||
|
|
||||||
int connect_to_imap_server(int sd, int *seq, char *server, char *username, char *password, int port, struct __data *data, int use_ssl);
|
int connect_to_imap_server(int sd, int *seq, char *username, char *password, int port, struct __data *data, int use_ssl);
|
||||||
int list_folders(int sd, int *seq, char *folders, int foldersize, int use_ssl, struct __data *data);
|
int list_folders(int sd, int *seq, char *folders, int foldersize, int use_ssl, struct __data *data);
|
||||||
int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sdata, struct __data *data, int use_ssl, struct __config *cfg);
|
int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sdata, struct __data *data, int use_ssl, struct __config *cfg);
|
||||||
int connect_to_pop3_server(int sd, char *server, char *username, char *password, int port, struct __data *data, int use_ssl);
|
int connect_to_pop3_server(int sd, char *username, char *password, int port, struct __data *data, int use_ssl);
|
||||||
int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, int use_ssl, struct __config *cfg);
|
int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, int use_ssl, struct __config *cfg);
|
||||||
void close_connection(int sd, struct __data *data, int use_ssl);
|
void close_connection(int sd, struct __data *data, int use_ssl);
|
||||||
|
|
||||||
@ -254,19 +257,39 @@ int import_from_imap_server(char *server, char *username, char *password, int po
|
|||||||
char *p, puf[SMALLBUFSIZE];
|
char *p, puf[SMALLBUFSIZE];
|
||||||
char muf[SMALLBUFSIZE];
|
char muf[SMALLBUFSIZE];
|
||||||
char folders[MAXBUFSIZE];
|
char folders[MAXBUFSIZE];
|
||||||
|
char port_string[6];
|
||||||
|
struct addrinfo hints, *res;
|
||||||
|
|
||||||
|
snprintf(port_string, sizeof(port_string)-1, "%d", port);
|
||||||
|
|
||||||
|
memset(&hints, 0, sizeof(hints));
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
|
if((rc = getaddrinfo(server, port_string, &hints, &res)) != 0){
|
||||||
|
printf("getaddrinfo for '%s': %s\n", server, gai_strerror(rc));
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
|
||||||
if(port == 993) use_ssl = 1;
|
if(port == 993) use_ssl = 1;
|
||||||
|
|
||||||
|
|
||||||
if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
|
if((sd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1){
|
||||||
printf("cannot create socket\n");
|
printf("cannot create socket\n");
|
||||||
return ERR;
|
ret = ERR;
|
||||||
|
goto ENDE_IMAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(connect_to_imap_server(sd, &seq, server, username, password, port, data, use_ssl) == ERR){
|
if(connect(sd, res->ai_addr, res->ai_addrlen) == -1){
|
||||||
|
printf("connect()\n");
|
||||||
|
ret = ERR;
|
||||||
|
goto ENDE_IMAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(connect_to_imap_server(sd, &seq, username, password, port, data, use_ssl) == ERR){
|
||||||
close(sd);
|
close(sd);
|
||||||
return ERR;
|
ret = ERR;
|
||||||
|
goto ENDE_IMAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -294,38 +317,64 @@ int import_from_imap_server(char *server, char *username, char *password, int po
|
|||||||
|
|
||||||
if(quiet == 0) printf("processing folder: %s... ", puf);
|
if(quiet == 0) printf("processing folder: %s... ", puf);
|
||||||
|
|
||||||
rc = process_imap_folder(sd, &seq, puf, sdata, data, use_ssl, cfg);
|
if(process_imap_folder(sd, &seq, puf, sdata, data, use_ssl, cfg) == ERR) ret = ERR;
|
||||||
if(rc == ERR) ret = ERR;
|
|
||||||
|
|
||||||
} while(p);
|
} while(p);
|
||||||
|
|
||||||
|
|
||||||
close_connection(sd, data, use_ssl);
|
close_connection(sd, data, use_ssl);
|
||||||
|
|
||||||
|
ENDE_IMAP:
|
||||||
|
freeaddrinfo(res);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int import_from_pop3_server(char *server, char *username, char *password, int port, struct session_data *sdata, struct __data *data, struct __config *cfg){
|
int import_from_pop3_server(char *server, char *username, char *password, int port, struct session_data *sdata, struct __data *data, struct __config *cfg){
|
||||||
int rc=ERR, ret=OK, sd, use_ssl=0;
|
int rc, ret=OK, sd, use_ssl=0;
|
||||||
|
char port_string[6];
|
||||||
|
struct addrinfo hints, *res;
|
||||||
|
|
||||||
|
snprintf(port_string, sizeof(port_string)-1, "%d", port);
|
||||||
|
|
||||||
|
memset(&hints, 0, sizeof(hints));
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
|
if((rc = getaddrinfo(server, port_string, &hints, &res)) != 0){
|
||||||
|
printf("getaddrinfo for '%s': %s\n", server, gai_strerror(rc));
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
|
||||||
if(port == 995) use_ssl = 1;
|
if(port == 995) use_ssl = 1;
|
||||||
|
|
||||||
if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
|
if((sd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1){
|
||||||
printf("cannot create socket\n");
|
printf("cannot create socket\n");
|
||||||
return ERR;
|
ret = ERR;
|
||||||
|
goto ENDE_POP3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(connect_to_pop3_server(sd, server, username, password, port, data, use_ssl) == ERR){
|
if(connect(sd, res->ai_addr, res->ai_addrlen) == -1){
|
||||||
|
printf("connect()\n");
|
||||||
|
ret = ERR;
|
||||||
|
goto ENDE_POP3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(connect_to_pop3_server(sd, username, password, port, data, use_ssl) == ERR){
|
||||||
close(sd);
|
close(sd);
|
||||||
return ERR;
|
ret = ERR;
|
||||||
|
goto ENDE_POP3;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = process_pop3_emails(sd, sdata, data, use_ssl, cfg);
|
if(process_pop3_emails(sd, sdata, data, use_ssl, cfg) == ERR) ret = ERR;
|
||||||
if(rc == ERR) ret = ERR;
|
|
||||||
|
|
||||||
close_connection(sd, data, use_ssl);
|
close_connection(sd, data, use_ssl);
|
||||||
|
|
||||||
|
ENDE_POP3:
|
||||||
|
freeaddrinfo(res);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
src/pop3.c
16
src/pop3.c
@ -33,26 +33,12 @@ int is_last_complete_pop3_packet(char *s, int len){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int connect_to_pop3_server(int sd, char *server, char *username, char *password, int port, struct __data *data, int use_ssl){
|
int connect_to_pop3_server(int sd, char *username, char *password, int port, struct __data *data, int use_ssl){
|
||||||
int n;
|
int n;
|
||||||
char buf[MAXBUFSIZE];
|
char buf[MAXBUFSIZE];
|
||||||
unsigned long host=0;
|
|
||||||
struct sockaddr_in remote_addr;
|
|
||||||
X509* server_cert;
|
X509* server_cert;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
host = resolve_host(server);
|
|
||||||
|
|
||||||
remote_addr.sin_family = AF_INET;
|
|
||||||
remote_addr.sin_port = htons(port);
|
|
||||||
remote_addr.sin_addr.s_addr = host;
|
|
||||||
bzero(&(remote_addr.sin_zero),8);
|
|
||||||
|
|
||||||
if(connect(sd, (struct sockaddr *)&remote_addr, sizeof(struct sockaddr)) == -1){
|
|
||||||
printf("connect()\n");
|
|
||||||
return ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(use_ssl == 1){
|
if(use_ssl == 1){
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user