2011-11-14 15:57:52 +01:00
/*
* message . c , SJ
*/
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <time.h>
# include <sys/types.h>
# include <sys/mman.h>
# include <sys/socket.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <unistd.h>
# include <syslog.h>
# include <piler.h>
# include <zlib.h>
2012-02-07 17:21:23 +01:00
int prepare_a_mysql_statement ( struct session_data * sdata , MYSQL_STMT * * stmt , char * s ) {
* stmt = mysql_stmt_init ( & ( sdata - > mysql ) ) ;
if ( ! * stmt ) {
syslog ( LOG_PRIORITY , " %s: mysql_stmt_init() error " , sdata - > ttmpfile ) ;
return ERR ;
}
if ( mysql_stmt_prepare ( * stmt , s , strlen ( s ) ) ) {
syslog ( LOG_PRIORITY , " %s: mysql_stmt_prepare() error: %s => sql: %s " , sdata - > ttmpfile , mysql_stmt_error ( * stmt ) , s ) ;
return ERR ;
}
return OK ;
}
int is_existing_message_id ( struct session_data * sdata , struct _state * state , struct __data * data , struct __config * cfg ) {
2011-11-14 15:57:52 +01:00
int rc = 0 ;
char s [ SMALLBUFSIZE ] ;
MYSQL_STMT * stmt ;
MYSQL_BIND bind [ 1 ] ;
my_bool is_null [ 1 ] ;
unsigned long len = 0 ;
snprintf ( s , SMALLBUFSIZE - 1 , " SELECT message_id FROM %s WHERE message_id=? " , SQL_METADATA_TABLE ) ;
2012-02-07 17:21:23 +01:00
if ( prepare_a_mysql_statement ( sdata , & stmt , s ) = = ERR ) goto ENDE ;
2011-11-14 15:57:52 +01:00
memset ( bind , 0 , sizeof ( bind ) ) ;
bind [ 0 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 0 ] . buffer = state - > message_id ;
bind [ 0 ] . is_null = 0 ;
len = strlen ( state - > message_id ) ; bind [ 0 ] . length = & len ;
if ( mysql_stmt_bind_param ( stmt , bind ) ) {
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_bind_param() error: %s " , sdata - > ttmpfile , SQL_METADATA_TABLE , mysql_stmt_error ( stmt ) ) ;
2012-01-29 09:02:21 +01:00
goto CLOSE ;
2011-11-14 15:57:52 +01:00
}
if ( mysql_stmt_execute ( stmt ) ) {
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_execute() error: %s " , sdata - > ttmpfile , SQL_METADATA_TABLE , mysql_stmt_error ( stmt ) ) ;
2012-01-29 09:02:21 +01:00
goto CLOSE ;
2011-11-14 15:57:52 +01:00
}
memset ( bind , 0 , sizeof ( bind ) ) ;
bind [ 0 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 0 ] . buffer = & s [ 0 ] ;
bind [ 0 ] . buffer_length = sizeof ( s ) - 1 ;
bind [ 0 ] . is_null = & is_null [ 0 ] ;
bind [ 0 ] . length = & len ;
if ( mysql_stmt_bind_result ( stmt , bind ) ) {
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_bind_result() error: %s " , sdata - > ttmpfile , SQL_METADATA_TABLE , mysql_stmt_error ( stmt ) ) ;
2012-01-29 09:02:21 +01:00
goto CLOSE ;
2011-11-14 15:57:52 +01:00
}
if ( mysql_stmt_store_result ( stmt ) ) {
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_store_result() error: %s " , sdata - > ttmpfile , SQL_METADATA_TABLE , mysql_stmt_error ( stmt ) ) ;
2012-01-29 09:02:21 +01:00
goto CLOSE ;
2011-11-14 15:57:52 +01:00
}
if ( ! mysql_stmt_fetch ( stmt ) ) {
syslog ( LOG_PRIORITY , " %s: found message_id:*%s*(%ld) null=%d " , sdata - > ttmpfile , s , len , is_null [ 0 ] ) ;
if ( is_null [ 0 ] = = 0 ) rc = 1 ;
}
2012-01-29 09:02:21 +01:00
CLOSE :
2011-11-14 15:57:52 +01:00
mysql_stmt_close ( stmt ) ;
ENDE :
return rc ;
}
2012-08-23 10:23:58 +02:00
int store_index_data ( struct session_data * sdata , struct _state * state , struct __data * data , uint64 id , struct __config * cfg ) {
2012-01-29 09:02:21 +01:00
int rc = ERR ;
2011-12-03 23:05:00 +01:00
char * subj , s [ SMALLBUFSIZE ] ;
MYSQL_STMT * stmt ;
2012-01-14 09:53:26 +01:00
MYSQL_BIND bind [ 7 ] ;
unsigned long len [ 7 ] ;
2011-11-14 15:57:52 +01:00
2011-11-28 14:21:14 +01:00
subj = state - > b_subject ;
if ( * subj = = ' ' ) subj + + ;
2011-11-14 15:57:52 +01:00
2012-08-23 10:23:58 +02:00
snprintf ( s , sizeof ( s ) - 1 , " INSERT INTO %s (`id`, `from`, `to`, `fromdomain`, `todomain`, `subject`, `body`, `arrived`, `sent`, `size`, `direction`, `folder`, `attachments`, `attachment_types`) values(%llu,?,?,?,?,?,?,%ld,%ld,%d,%d,%d,%d,?) " , SQL_SPHINX_TABLE , id , sdata - > now , sdata - > sent , sdata - > tot_len , sdata - > direction , data - > folder , state - > n_attachments ) ;
2011-11-14 15:57:52 +01:00
2012-02-07 17:21:23 +01:00
if ( prepare_a_mysql_statement ( sdata , & stmt , s ) = = ERR ) return rc ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
2011-12-05 17:18:03 +01:00
fix_email_address_for_sphinx ( state - > b_from ) ;
fix_email_address_for_sphinx ( state - > b_to ) ;
2012-01-14 09:53:26 +01:00
fix_email_address_for_sphinx ( state - > b_from_domain ) ;
fix_email_address_for_sphinx ( state - > b_to_domain ) ;
2011-12-05 17:18:03 +01:00
2011-12-03 23:05:00 +01:00
memset ( bind , 0 , sizeof ( bind ) ) ;
bind [ 0 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 0 ] . buffer = state - > b_from ;
bind [ 0 ] . is_null = 0 ;
len [ 0 ] = strlen ( state - > b_from ) ; bind [ 0 ] . length = & len [ 0 ] ;
bind [ 1 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 1 ] . buffer = state - > b_to ;
bind [ 1 ] . is_null = 0 ;
len [ 1 ] = strlen ( state - > b_to ) ; bind [ 1 ] . length = & len [ 1 ] ;
bind [ 2 ] . buffer_type = MYSQL_TYPE_STRING ;
2012-01-14 09:53:26 +01:00
bind [ 2 ] . buffer = state - > b_from_domain ;
2011-12-03 23:05:00 +01:00
bind [ 2 ] . is_null = 0 ;
2012-01-14 09:53:26 +01:00
len [ 2 ] = strlen ( state - > b_from_domain ) ; bind [ 2 ] . length = & len [ 2 ] ;
2011-12-03 23:05:00 +01:00
bind [ 3 ] . buffer_type = MYSQL_TYPE_STRING ;
2012-01-14 09:53:26 +01:00
bind [ 3 ] . buffer = state - > b_to_domain ;
2011-12-03 23:05:00 +01:00
bind [ 3 ] . is_null = 0 ;
2012-01-14 09:53:26 +01:00
len [ 3 ] = strlen ( state - > b_to_domain ) ; bind [ 3 ] . length = & len [ 3 ] ;
2011-12-03 23:05:00 +01:00
2011-12-30 15:52:59 +01:00
bind [ 4 ] . buffer_type = MYSQL_TYPE_STRING ;
2012-01-14 09:53:26 +01:00
bind [ 4 ] . buffer = subj ;
2011-12-30 15:52:59 +01:00
bind [ 4 ] . is_null = 0 ;
2012-01-14 09:53:26 +01:00
len [ 4 ] = strlen ( subj ) ; bind [ 4 ] . length = & len [ 4 ] ;
bind [ 5 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 5 ] . buffer = state - > b_body ;
bind [ 5 ] . is_null = 0 ;
len [ 5 ] = strlen ( state - > b_body ) ; bind [ 5 ] . length = & len [ 5 ] ;
bind [ 6 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 6 ] . buffer = sdata - > attachments ;
bind [ 6 ] . is_null = 0 ;
len [ 6 ] = strlen ( sdata - > attachments ) ; bind [ 6 ] . length = & len [ 6 ] ;
2011-12-30 15:52:59 +01:00
2011-12-03 23:05:00 +01:00
if ( mysql_stmt_bind_param ( stmt , bind ) ) {
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_bind_param() error: %s " , sdata - > ttmpfile , SQL_SPHINX_TABLE , mysql_stmt_error ( stmt ) ) ;
2012-01-29 09:02:21 +01:00
goto CLOSE ;
2011-12-03 23:05:00 +01:00
}
2012-01-29 09:02:21 +01:00
if ( mysql_stmt_execute ( stmt ) ) {
2011-12-03 23:05:00 +01:00
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_execute error: *%s* " , sdata - > ttmpfile , SQL_SPHINX_TABLE , mysql_error ( & ( sdata - > mysql ) ) ) ;
2012-01-29 09:02:21 +01:00
goto CLOSE ;
2011-12-03 23:05:00 +01:00
}
2012-01-29 09:02:21 +01:00
rc = OK ;
2011-12-03 23:05:00 +01:00
2012-01-29 09:02:21 +01:00
CLOSE :
mysql_stmt_close ( stmt ) ;
return rc ;
2011-12-03 23:05:00 +01:00
}
2012-10-05 14:27:03 +02:00
uint64 get_metaid_by_messageid ( struct session_data * sdata , char * message_id , struct __config * cfg ) {
unsigned long len = 0 ;
uint64 id = 0 ;
char s [ SMALLBUFSIZE ] ;
MYSQL_STMT * stmt ;
MYSQL_BIND bind [ 1 ] ;
snprintf ( s , sizeof ( s ) - 1 , " SELECT id FROM %s WHERE message_id=? " , SQL_METADATA_TABLE ) ;
if ( prepare_a_mysql_statement ( sdata , & stmt , s ) = = ERR ) return id ;
memset ( bind , 0 , sizeof ( bind ) ) ;
bind [ 0 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 0 ] . buffer = message_id ;
bind [ 0 ] . is_null = 0 ;
len = strlen ( message_id ) ; bind [ 0 ] . length = & len ;
if ( mysql_stmt_bind_param ( stmt , bind ) ) {
goto CLOSE ;
}
if ( mysql_stmt_execute ( stmt ) ) {
goto CLOSE ;
}
memset ( bind , 0 , sizeof ( bind ) ) ;
bind [ 0 ] . buffer_type = MYSQL_TYPE_LONGLONG ;
bind [ 0 ] . buffer = ( char * ) & id ;
bind [ 0 ] . is_null = 0 ;
bind [ 0 ] . length = 0 ;
if ( mysql_stmt_bind_result ( stmt , bind ) ) {
goto CLOSE ;
}
if ( mysql_stmt_store_result ( stmt ) ) {
goto CLOSE ;
}
mysql_stmt_fetch ( stmt ) ;
CLOSE :
mysql_stmt_close ( stmt ) ;
return id ;
}
int store_recipients ( struct session_data * sdata , char * to , uint64 id , int log_errors , struct __config * cfg ) {
2012-09-04 14:49:56 +02:00
int ret = OK , n = 0 ;
2012-01-09 23:15:39 +01:00
char * p , * q , s [ SMALLBUFSIZE ] , puf [ SMALLBUFSIZE ] ;
2011-12-03 23:05:00 +01:00
MYSQL_STMT * stmt ;
2012-01-09 23:15:39 +01:00
MYSQL_BIND bind [ 2 ] ;
unsigned long len [ 2 ] ;
2011-12-03 23:05:00 +01:00
2012-01-09 23:15:39 +01:00
snprintf ( s , sizeof ( s ) - 1 , " INSERT INTO %s (`id`,`to`,`todomain`) VALUES('%llu',?,?) " , SQL_RECIPIENT_TABLE , id ) ;
2011-12-03 23:05:00 +01:00
2012-02-07 17:21:23 +01:00
if ( prepare_a_mysql_statement ( sdata , & stmt , s ) = = ERR ) return ERR ;
2011-12-03 23:05:00 +01:00
p = to ;
do {
p = split_str ( p , " " , puf , sizeof ( puf ) - 1 ) ;
2012-01-09 23:15:39 +01:00
q = strchr ( puf , ' @ ' ) ;
if ( q & & strlen ( q ) > 3 & & does_it_seem_like_an_email_address ( puf ) = = 1 ) {
q + + ;
2011-12-03 23:05:00 +01:00
memset ( bind , 0 , sizeof ( bind ) ) ;
bind [ 0 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 0 ] . buffer = & puf [ 0 ] ;
bind [ 0 ] . is_null = 0 ;
len [ 0 ] = strlen ( puf ) ; bind [ 0 ] . length = & len [ 0 ] ;
2012-01-09 23:15:39 +01:00
bind [ 1 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 1 ] . buffer = q ;
bind [ 1 ] . is_null = 0 ;
len [ 1 ] = strlen ( q ) ; bind [ 1 ] . length = & len [ 1 ] ;
2011-12-03 23:05:00 +01:00
if ( mysql_stmt_bind_param ( stmt , bind ) ) {
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_bind_param() error: %s " , sdata - > ttmpfile , SQL_RECIPIENT_TABLE , mysql_stmt_error ( stmt ) ) ;
2012-01-29 09:02:21 +01:00
ret = ERR ;
goto CLOSE ;
2011-12-03 23:05:00 +01:00
}
2012-10-05 14:27:03 +02:00
if ( mysql_stmt_execute ( stmt ) & & log_errors = = 1 ) {
2011-12-03 23:05:00 +01:00
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_execute error: *%s* " , sdata - > ttmpfile , SQL_RECIPIENT_TABLE , mysql_error ( & ( sdata - > mysql ) ) ) ;
ret = ERR ;
}
2012-09-04 14:49:56 +02:00
else n + + ;
2011-12-03 23:05:00 +01:00
}
} while ( p ) ;
2012-01-29 09:02:21 +01:00
CLOSE :
mysql_stmt_close ( stmt ) ;
2012-09-04 14:49:56 +02:00
if ( cfg - > verbosity > = _LOG_DEBUG ) syslog ( LOG_PRIORITY , " %s: added %d recipients " , sdata - > ttmpfile , n ) ;
2011-12-03 23:05:00 +01:00
return ret ;
2011-11-14 15:57:52 +01:00
}
2012-08-23 10:23:58 +02:00
int store_meta_data ( struct session_data * sdata , struct _state * state , struct __data * data , struct __config * cfg ) {
2011-12-03 23:05:00 +01:00
int rc , ret = ERR ;
2012-02-10 14:06:00 +01:00
char * subj , * p , s [ MAXBUFSIZE ] , s2 [ SMALLBUFSIZE ] , vcode [ 2 * DIGEST_LENGTH + 1 ] , ref [ 2 * DIGEST_LENGTH + 1 ] ;
2011-11-14 15:57:52 +01:00
MYSQL_STMT * stmt ;
2012-02-10 14:06:00 +01:00
MYSQL_BIND bind [ 4 ] ;
unsigned long len [ 4 ] ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
my_ulonglong id = 0 ;
2011-11-28 14:21:14 +01:00
subj = state - > b_subject ;
if ( * subj = = ' ' ) subj + + ;
2012-02-19 22:59:47 +01:00
snprintf ( s , sizeof ( s ) - 1 , " %llu+%s%s%s%ld%ld%ld%d%d%d%d%s%s%s " , id , subj , state - > b_from , state - > message_id , sdata - > now , sdata - > sent , sdata - > retained , sdata - > tot_len , sdata - > hdr_len , sdata - > direction , state - > n_attachments , sdata - > ttmpfile , sdata - > digest , sdata - > bodydigest ) ;
2012-02-10 14:06:00 +01:00
2012-01-14 09:53:26 +01:00
digest_string ( s , & vcode [ 0 ] ) ;
2012-02-10 14:06:00 +01:00
memset ( ref , 0 , sizeof ( ref ) ) ;
if ( strlen ( state - > reference ) > 10 ) digest_string ( state - > reference , & ref [ 0 ] ) ;
2012-01-14 09:53:26 +01:00
2012-02-19 22:59:47 +01:00
snprintf ( s , MAXBUFSIZE - 1 , " INSERT INTO %s (`from`,`fromdomain`,`subject`,`spam`,`arrived`,`sent`,`retained`,`size`,`hlen`,`direction`,`attachments`,`piler_id`,`message_id`,`reference`,`digest`,`bodydigest`,`vcode`) VALUES(?,?,?,%d,%ld,%ld,%ld,%d,%d,%d,%d,'%s',?,'%s','%s','%s','%s') " , SQL_METADATA_TABLE , sdata - > spam_message , sdata - > now , sdata - > sent , sdata - > retained , sdata - > tot_len , sdata - > hdr_len , sdata - > direction , state - > n_attachments , sdata - > ttmpfile , ref , sdata - > digest , sdata - > bodydigest , vcode ) ;
2011-11-14 15:57:52 +01:00
if ( cfg - > verbosity > = _LOG_DEBUG ) syslog ( LOG_PRIORITY , " %s: meta sql: *%s* " , sdata - > ttmpfile , s ) ;
2012-02-07 17:21:23 +01:00
if ( prepare_a_mysql_statement ( sdata , & stmt , s ) = = ERR ) return ERR ;
memset ( s2 , 0 , sizeof ( s2 ) ) ;
2011-11-14 15:57:52 +01:00
2012-02-07 17:21:23 +01:00
p = state - > b_from ;
do {
memset ( s2 , 0 , sizeof ( s2 ) ) ;
p = split ( p , ' ' , s2 , sizeof ( s2 ) - 1 ) ;
if ( s2 [ 0 ] = = ' \0 ' ) continue ;
if ( does_it_seem_like_an_email_address ( s2 ) = = 1 ) { break ; }
} while ( p ) ;
2011-11-14 15:57:52 +01:00
if ( strlen ( state - > b_to ) < 5 ) {
2012-01-09 23:15:39 +01:00
snprintf ( state - > b_to , SMALLBUFSIZE - 1 , " undisclosed-recipients@no.domain " ) ;
2011-11-14 15:57:52 +01:00
}
2011-12-03 23:05:00 +01:00
memset ( bind , 0 , sizeof ( bind ) ) ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
bind [ 0 ] . buffer_type = MYSQL_TYPE_STRING ;
2012-02-07 17:21:23 +01:00
bind [ 0 ] . buffer = & s2 [ 0 ] ;
2011-12-03 23:05:00 +01:00
bind [ 0 ] . is_null = 0 ;
2012-02-07 17:21:23 +01:00
len [ 0 ] = strlen ( s2 ) ; bind [ 0 ] . length = & len [ 0 ] ;
2011-11-14 15:57:52 +01:00
2012-11-28 22:15:11 +01:00
bind [ 1 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 1 ] . buffer = state - > b_from_domain ;
bind [ 1 ] . is_null = 0 ;
len [ 1 ] = strlen ( state - > b_from_domain ) ; bind [ 1 ] . length = & len [ 1 ] ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
bind [ 2 ] . buffer_type = MYSQL_TYPE_STRING ;
2012-01-09 23:15:39 +01:00
bind [ 2 ] . buffer = subj ;
2011-12-03 23:05:00 +01:00
bind [ 2 ] . is_null = 0 ;
2012-01-09 23:15:39 +01:00
len [ 2 ] = strlen ( subj ) ; bind [ 2 ] . length = & len [ 2 ] ;
bind [ 3 ] . buffer_type = MYSQL_TYPE_STRING ;
bind [ 3 ] . buffer = state - > message_id ;
bind [ 3 ] . is_null = 0 ;
len [ 3 ] = strlen ( state - > message_id ) ; bind [ 3 ] . length = & len [ 3 ] ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
if ( mysql_stmt_bind_param ( stmt , bind ) ) {
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_bind_param() error: %s " , sdata - > ttmpfile , SQL_METADATA_TABLE , mysql_stmt_error ( stmt ) ) ;
2012-01-29 09:02:21 +01:00
goto CLOSE ;
2011-12-03 23:05:00 +01:00
}
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
rc = mysql_stmt_execute ( stmt ) ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
if ( rc ) {
syslog ( LOG_PRIORITY , " %s: %s.mysql_stmt_execute() error: *%s* " , sdata - > ttmpfile , SQL_METADATA_TABLE , mysql_error ( & ( sdata - > mysql ) ) ) ;
ret = ERR_EXISTS ;
}
else {
id = mysql_stmt_insert_id ( stmt ) ;
2012-01-09 23:15:39 +01:00
2012-10-05 14:27:03 +02:00
rc = store_recipients ( sdata , state - > b_to , id , 1 , cfg ) ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
if ( cfg - > verbosity > = _LOG_DEBUG ) syslog ( LOG_PRIORITY , " %s: stored recipients, rc=%d " , sdata - > ttmpfile , rc ) ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
if ( rc = = OK ) {
2012-01-09 23:15:39 +01:00
2012-08-23 10:23:58 +02:00
rc = store_index_data ( sdata , state , data , id , cfg ) ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
if ( cfg - > verbosity > = _LOG_DEBUG ) syslog ( LOG_PRIORITY , " %s: stored indexdata, rc=%d " , sdata - > ttmpfile , rc ) ;
2011-11-14 15:57:52 +01:00
2011-12-03 23:05:00 +01:00
if ( rc = = OK )
ret = OK ;
2011-11-14 15:57:52 +01:00
}
2011-12-03 23:05:00 +01:00
}
2011-11-14 15:57:52 +01:00
2012-01-29 09:02:21 +01:00
CLOSE :
mysql_stmt_close ( stmt ) ;
2011-11-14 15:57:52 +01:00
return ret ;
}
2012-12-15 21:25:36 +01:00
void remove_stripped_attachments ( struct _state * state ) {
int i ;
for ( i = 1 ; i < = state - > n_attachments ; i + + ) unlink ( state - > attachments [ i ] . internalname ) ;
}
2012-02-07 17:21:23 +01:00
int process_message ( struct session_data * sdata , struct _state * state , struct __data * data , struct __config * cfg ) {
2011-11-19 21:25:44 +01:00
int i , rc ;
2012-10-05 14:27:03 +02:00
uint64 id = 0 ;
2011-11-14 15:57:52 +01:00
/* discard if existing message_id */
2012-02-07 17:21:23 +01:00
if ( is_existing_message_id ( sdata , state , data , cfg ) = = 1 ) {
2012-12-15 21:25:36 +01:00
remove_stripped_attachments ( state ) ;
2012-10-05 14:27:03 +02:00
if ( strlen ( state - > b_journal_to ) > 0 ) {
id = get_metaid_by_messageid ( sdata , state - > message_id , cfg ) ;
if ( cfg - > verbosity > = _LOG_DEBUG ) syslog ( LOG_PRIORITY , " %s: trying to add journal rcpt (%s) to id=%llu for message-id: '%s' " , sdata - > ttmpfile , state - > b_journal_to , id , state - > message_id ) ;
store_recipients ( sdata , state - > b_journal_to , id , 0 , cfg ) ;
}
2011-11-14 15:57:52 +01:00
return ERR_EXISTS ;
}
2011-11-23 12:24:21 +01:00
/* store base64 encoded file attachments */
2011-11-19 21:25:44 +01:00
2011-11-23 12:24:21 +01:00
if ( state - > n_attachments > 0 ) {
rc = store_attachments ( sdata , state , cfg ) ;
2011-11-19 21:25:44 +01:00
2011-11-23 12:24:21 +01:00
for ( i = 1 ; i < = state - > n_attachments ; i + + ) {
unlink ( state - > attachments [ i ] . internalname ) ;
}
if ( rc ) return ERR ;
2011-11-19 21:25:44 +01:00
}
rc = store_file ( sdata , sdata - > tmpframe , 0 , 0 , cfg ) ;
if ( rc = = 0 ) {
syslog ( LOG_PRIORITY , " %s: error storing message: %s " , sdata - > ttmpfile , sdata - > tmpframe ) ;
return ERR ;
}
2011-11-14 15:57:52 +01:00
2012-02-19 22:59:47 +01:00
sdata - > retained + = query_retain_period ( data - > retention_rules , state , sdata - > tot_len , sdata - > spam_message , cfg ) ;
2012-08-23 10:23:58 +02:00
rc = store_meta_data ( sdata , state , data , cfg ) ;
2011-11-14 15:57:52 +01:00
if ( cfg - > verbosity > = _LOG_DEBUG ) syslog ( LOG_PRIORITY , " %s: stored metadata, rc=%d " , sdata - > ttmpfile , rc ) ;
2012-05-29 14:08:56 +02:00
if ( rc = = ERR_EXISTS ) {
remove_stored_message_files ( sdata , state , cfg ) ;
return ERR_EXISTS ;
}
2011-11-14 15:57:52 +01:00
return OK ;
}