mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 21:51:59 +01:00
added tnef support
This commit is contained in:
parent
309ad52414
commit
1229e10bfc
12
configure
vendored
12
configure
vendored
@ -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
|
||||
|
@ -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
|
||||
|
@ -15,6 +15,7 @@
|
||||
#undef HAVE_XLS2CSV
|
||||
#undef HAVE_PPTHTML
|
||||
#undef HAVE_UNRTF
|
||||
#undef HAVE_TNEF
|
||||
#undef HAVE_ZIP
|
||||
|
||||
#undef HAVE_STARTTLS
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#define VERSION "0.1.25-master-branch"
|
||||
|
||||
#define BUILD 839
|
||||
#define BUILD 844
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
|
@ -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<strlen(p); i++){
|
||||
memcpy(s, p+i, 4);
|
||||
s[4] = '\0';
|
||||
|
||||
i += 3;
|
||||
|
||||
/* safety check against abnormally long lines */
|
||||
|
||||
if(len + 3 > 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<plen; i++){
|
||||
for(i=0; i<plen; i+=4){
|
||||
memcpy(s, p+i, 4);
|
||||
s[4] = '\0';
|
||||
|
||||
i += 3;
|
||||
decodedlen = 3;
|
||||
|
||||
/* safety check against abnormally long lines */
|
||||
|
||||
if(len + 3 > 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <piler.h>
|
||||
|
||||
@ -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;
|
||||
|
13
src/misc.c
13
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; i<buflen; i++){
|
||||
*(buf+i) = alphanum[rand() % len];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void create_id(char *id, unsigned char server_id){
|
||||
int i;
|
||||
unsigned char buf[RND_STR_LEN/2];
|
||||
|
@ -24,6 +24,7 @@ char *split(char *row, int ch, char *s, int size);
|
||||
char *split_str(char *row, char *what, char *s, int size);
|
||||
int trimBuffer(char *s);
|
||||
int extractEmail(char *rawmail, char *email);
|
||||
void make_random_string(char *buf, int buflen);
|
||||
void create_id(char *id, unsigned char server_id);
|
||||
int get_random_bytes(unsigned char *buf, int len, unsigned char server_id);
|
||||
int readFromEntropyPool(int fd, void *_s, size_t n);
|
||||
|
@ -211,7 +211,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
||||
}
|
||||
|
||||
if(take_into_pieces == 1){
|
||||
if(state->message_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;
|
||||
}
|
||||
|
@ -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";
|
||||
|
||||
|
@ -469,6 +469,8 @@ int main(int argc, char **argv){
|
||||
|
||||
for(i=0; i<MBOX_ARGS; i++) mbox[i] = NULL;
|
||||
|
||||
srand(getpid());
|
||||
|
||||
data.folder = 0;
|
||||
data.recursive_folder_names = 0;
|
||||
|
||||
|
@ -206,6 +206,7 @@ int main(int argc, char **argv){
|
||||
|
||||
(void) openlog("reindex", LOG_PID, LOG_MAIL);
|
||||
|
||||
srand(getpid());
|
||||
|
||||
cfg = read_config(configfile);
|
||||
|
||||
|
@ -51,6 +51,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
||||
}
|
||||
#endif
|
||||
|
||||
srand(getpid());
|
||||
|
||||
state = SMTP_STATE_INIT;
|
||||
|
||||
|
@ -24,6 +24,7 @@ int main(int argc, char **argv){
|
||||
struct __data data;
|
||||
char *rule;
|
||||
|
||||
srand(getpid());
|
||||
|
||||
if(argc < 2){
|
||||
fprintf(stderr, "usage: %s <message>\n", argv[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user