diff --git a/configure b/configure index 27b23cdd..3256598d 100755 --- a/configure +++ b/configure @@ -3451,6 +3451,7 @@ catppt="no" ppthtml="no" xls2csv="no" unrtf="no" +tnef="no" have_static_build="no" @@ -4706,6 +4707,16 @@ _ACEOF fi +if test z`which tnef 2>/dev/null` != "z"; then + tnef=`which tnef` + +cat >>confdefs.h <<_ACEOF +#define HAVE_TNEF "$tnef" +_ACEOF + +fi + + if test "$have_tweak_sent_time" = "yes"; then cat >>confdefs.h <<_ACEOF @@ -4723,6 +4734,7 @@ echo "catppt: $catppt" echo "ppthtml: $ppthtml" echo "xls2csv: $xls2csv" echo "unrtf: $unrtf" +echo "tnef: $tnef" id -u $RUNNING_USER 2>/dev/null 1>/dev/null diff --git a/configure.in b/configure.in index 3ac7ad27..d6b9b08a 100644 --- a/configure.in +++ b/configure.in @@ -52,6 +52,7 @@ catppt="no" ppthtml="no" xls2csv="no" unrtf="no" +tnef="no" have_static_build="no" @@ -448,6 +449,12 @@ if test z`which unrtf 2>/dev/null` != "z"; then fi +if test z`which tnef 2>/dev/null` != "z"; then + tnef=`which tnef` + AC_DEFINE_UNQUOTED(HAVE_TNEF, "$tnef", [path to tnef]) +fi + + if test "$have_tweak_sent_time" = "yes"; then AC_DEFINE_UNQUOTED(HAVE_TWEAK_SENT_TIME, 1, [tweak sent time]) fi @@ -461,6 +468,7 @@ echo "catppt: $catppt" echo "ppthtml: $ppthtml" echo "xls2csv: $xls2csv" echo "unrtf: $unrtf" +echo "tnef: $tnef" id -u $RUNNING_USER 2>/dev/null 1>/dev/null diff --git a/piler-config.h.in b/piler-config.h.in index 7c58d171..18280c14 100644 --- a/piler-config.h.in +++ b/piler-config.h.in @@ -15,6 +15,7 @@ #undef HAVE_XLS2CSV #undef HAVE_PPTHTML #undef HAVE_UNRTF +#undef HAVE_TNEF #undef HAVE_ZIP #undef HAVE_STARTTLS diff --git a/src/config.h b/src/config.h index e13a3745..ba44a903 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "0.1.25-master-branch" -#define BUILD 839 +#define BUILD 844 #define HOSTID "mailarchiver" diff --git a/src/decoder.c b/src/decoder.c index fa0f4470..ed1bf433 100644 --- a/src/decoder.c +++ b/src/decoder.c @@ -111,32 +111,12 @@ inline void pack_4_into_3(char *s, char *s2){ int decodeBase64(char *p){ - int i, len=0; - char s[5], s2[3], puf[MAXBUFSIZE]; + int len=0; + unsigned char puf[MAXBUFSIZE]; - if(strlen(p) < 4 || strlen(p) > MAXBUFSIZE/2) - return 0; + memset(puf, 0, sizeof(puf)); - for(i=0; i sizeof(puf)-1) break; - - if(strlen(s) == 4){ - pack_4_into_3(s, s2); - memcpy(puf+len, s2, 3); - - len += 3; - } - - } - - *(puf+len) = '\0'; + len = decode_base64_to_buffer(p, strlen(p), &puf[0], sizeof(puf)-1); snprintf(p, MAXBUFSIZE-1, "%s", puf); @@ -145,27 +125,29 @@ int decodeBase64(char *p){ int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen){ - int i, len=0; + int i, len=0, decodedlen; char s[5], s2[3]; if(plen < 4 || plen > blen) return 0; - for(i=0; i blen-1) break; + if(len + decodedlen > blen-1) break; if(strlen(s) == 4){ pack_4_into_3(s, s2); - memcpy(b+len, s2, 3); + if(s[3] == '=') decodedlen = 2; + if(s[2] == '=') decodedlen = 1; - len += 3; + memcpy(b+len, s2, decodedlen); + + len += decodedlen; } } diff --git a/src/extract.c b/src/extract.c index 459046c5..f7616960 100644 --- a/src/extract.c +++ b/src/extract.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -90,6 +91,47 @@ int extract_opendocument(struct session_data *sdata, struct _state *state, char } +int extract_tnef(struct session_data *sdata, struct _state *state, char *filename){ + int rc=0, n, rec=1; + char tmpdir[BUFLEN], buf[SMALLBUFSIZE]; + struct dirent **namelist; + + memset(tmpdir, 0, sizeof(tmpdir)); + make_random_string(&tmpdir[0], sizeof(tmpdir)-3); + + memcpy(&tmpdir[sizeof(tmpdir)-3], ".d", 2); + + printf("tmpname: %s, filename: %s\n", tmpdir, filename); + + if(mkdir(tmpdir, 0700)) return rc; + + snprintf(buf, sizeof(buf)-1, "%s -C %s %s", HAVE_TNEF, tmpdir, filename); + + system(buf); + + n = scandir(tmpdir, &namelist, NULL, alphasort); + if(n < 0) syslog(LOG_INFO, "error reading %s", tmpdir); + else { + while(n--){ + if(strcmp(namelist[n]->d_name, ".") && strcmp(namelist[n]->d_name, "..")){ + snprintf(buf, sizeof(buf)-1, "%s/%s", tmpdir, namelist[n]->d_name); + + extract_attachment_content(sdata, state, buf, get_attachment_extractor_by_filename(buf), &rec); + + unlink(buf); + } + + free(namelist[n]); + } + free(namelist); + } + + rmdir(tmpdir); + + return rc; +} + + int unzip_file(struct session_data *sdata, struct _state *state, char *filename, int *rec){ int errorp, i=0, len=0, fd; char *p, extracted_filename[SMALLBUFSIZE], buf[MAXBUFSIZE]; @@ -201,6 +243,13 @@ void extract_attachment_content(struct session_data *sdata, struct _state *state if(strcmp(type, "rtf") == 0) snprintf(cmd, sizeof(cmd)-1, "%s --text %s", HAVE_UNRTF, filename); #endif +#ifdef HAVE_TNEF + if(strcmp(type, "tnef") == 0){ + extract_tnef(sdata, state, filename); + return; + } +#endif + if(strlen(cmd) > 12){ read_content_with_popen(sdata, state, cmd); return; @@ -208,6 +257,7 @@ void extract_attachment_content(struct session_data *sdata, struct _state *state #ifdef HAVE_ZIP + if(strcmp(type, "odf") == 0){ extract_opendocument(sdata, state, filename, "content.xml"); return; diff --git a/src/misc.c b/src/misc.c index 098840ac..368689b7 100644 --- a/src/misc.c +++ b/src/misc.c @@ -211,6 +211,19 @@ int extractEmail(char *rawmail, char *email){ } +void make_random_string(char *buf, int buflen){ + int i, len; + static char alphanum[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + len = strlen(alphanum); + + for(i=0; imessage_state == MSG_BODY && state->fd != -1 && findnode(state->boundaries, buf) == NULL){ + if(state->message_state == MSG_BODY && state->fd != -1 && is_substr_in_hash(state->boundaries, buf) == 0){ //n = write(state->fd, buf, len); // WRITE if(len + state->abufpos > abuffersize-1){ write(state->fd, abuffer, state->abufpos); @@ -438,8 +438,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int strcasestr(buf, "multipart/report") || strcasestr(buf, "message/delivery-status") || strcasestr(buf, "text/rfc822-headers") || - strcasestr(buf, "message/rfc822") || - strcasestr(buf, "application/ms-tnef") + strcasestr(buf, "message/rfc822") ){ state->textplain = 1; } diff --git a/src/parser_utils.c b/src/parser_utils.c index b39c5084..b0631c60 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -703,7 +703,7 @@ char *determine_attachment_type(char *filename, char *type){ if(strncasecmp(type, "application/pdf", strlen("application/pdf")) == 0) return "pdf,"; - if(strncasecmp(type, "application/ms-tnef", strlen("application/ms-tnef")) == 0) return "winmail,"; + if(strncasecmp(type, "application/ms-tnef", strlen("application/ms-tnef")) == 0) return "tnef,"; if(strncasecmp(type, "application/msword", strlen("application/msword")) == 0) return "word,"; // a .csv file has the same type @@ -760,6 +760,8 @@ char *determine_attachment_type(char *filename, char *type){ char *get_attachment_extractor_by_filename(char *filename){ char *p; + if(strcasecmp(filename, "winmail.dat") == 0) return "tnef"; + p = strrchr(filename, '.'); if(!p) return "other"; diff --git a/src/pilerimport.c b/src/pilerimport.c index 89fc2f95..768f608d 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -469,6 +469,8 @@ int main(int argc, char **argv){ for(i=0; i\n", argv[0]);