mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 07:40:12 +01:00
revised ms journal handling
This commit is contained in:
parent
e5618dd39b
commit
80cee9f59c
@ -13,7 +13,7 @@
|
||||
|
||||
#define VERSION "0.1.23-master-branch"
|
||||
|
||||
#define BUILD 752
|
||||
#define BUILD 761
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
@ -87,6 +87,10 @@
|
||||
#define SQL_MESSAGES_VIEW "v_messages"
|
||||
#define SQL_ATTACHMENTS_VIEW "v_attachment"
|
||||
|
||||
#define SQL_PREPARED_STMT_SELECT_MESSAGE_ID "SELECT message_id FROM " SQL_METADATA_TABLE " WHERE message_id=?"
|
||||
#define SQL_PREPARED_STMT_GET_META_ID_BY_MESSAGE_ID "SELECT id FROM " SQL_METADATA_TABLE " WHERE message_id=?"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_RCPT_TABLE "INSERT INTO " SQL_RECIPIENT_TABLE " (`id`,`to`,`todomain`) VALUES(?,?,?)"
|
||||
|
||||
|
||||
/* Error codes */
|
||||
|
||||
|
@ -189,7 +189,7 @@ struct session_data {
|
||||
char bodydigest[2*DIGEST_LENGTH+1];
|
||||
char digest[2*DIGEST_LENGTH+1];
|
||||
time_t now, sent, delivered, retained;
|
||||
char ms_journal, ms_journal_dropped;
|
||||
char ms_journal;
|
||||
int journal_envelope_length, journal_bottom_length;
|
||||
#ifdef NEED_MYSQL
|
||||
MYSQL mysql;
|
||||
|
@ -47,16 +47,10 @@ int make_digests(struct session_data *sdata, struct __config *cfg){
|
||||
fd = open(sdata->filename, O_RDONLY);
|
||||
if(fd == -1) return -1;
|
||||
|
||||
if(sdata->ms_journal == 1 && sdata->journal_envelope_length < sizeof(buf)){
|
||||
n = read(fd, buf, sdata->journal_envelope_length);
|
||||
}
|
||||
|
||||
|
||||
while((n = read(fd, buf, sizeof(buf))) > 0){
|
||||
len += n;
|
||||
|
||||
if(sdata->ms_journal == 1 && len > sdata->tot_len) n -= len - sdata->tot_len;
|
||||
|
||||
SHA256_Update(&context2, buf, n);
|
||||
|
||||
body = (char *)&buf[0];
|
||||
|
@ -480,7 +480,6 @@ void init_session_data(struct session_data *sdata, unsigned char server_id){
|
||||
sdata->num_of_rcpt_to = 0;
|
||||
|
||||
sdata->ms_journal = 0;
|
||||
sdata->ms_journal_dropped = 0;
|
||||
sdata->journal_envelope_length = 0;
|
||||
sdata->journal_bottom_length = 0;
|
||||
|
||||
|
25
src/parser.c
25
src/parser.c
@ -84,8 +84,6 @@ struct _state parse_message(struct session_data *sdata, int take_into_pieces, st
|
||||
}
|
||||
|
||||
if(take_into_pieces == 1 && state.writebufpos > 0){
|
||||
if(sdata->ms_journal == 1) remove_trailing_journal_boundary(sdata, &state, &writebuffer[0]);
|
||||
|
||||
len = write(state.mfd, writebuffer, state.writebufpos);
|
||||
memset(writebuffer, 0, sizeof(writebuffer));
|
||||
state.writebufpos = 0;
|
||||
@ -95,10 +93,6 @@ struct _state parse_message(struct session_data *sdata, int take_into_pieces, st
|
||||
close(state.mfd); state.mfd = 0;
|
||||
}
|
||||
|
||||
if(sdata->ms_journal == 1){
|
||||
sdata->tot_len -= sdata->journal_envelope_length + sdata->journal_bottom_length;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return state;
|
||||
@ -201,11 +195,6 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
||||
}
|
||||
|
||||
|
||||
if(sdata->ms_journal_dropped == 0){
|
||||
sdata->journal_envelope_length += len;
|
||||
}
|
||||
|
||||
|
||||
if(state->message_rfc822 == 0 && (buf[0] == '\r' || buf[0] == '\n') ){
|
||||
state->message_state = MSG_BODY;
|
||||
|
||||
@ -243,7 +232,6 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
||||
state->saved_size += len;
|
||||
//n = write(state->mfd, buf, len); // WRITE
|
||||
if(len + state->writebufpos > writebuffersize-1){
|
||||
if(sdata->ms_journal == 1) remove_trailing_journal_boundary(sdata, state, writebuffer);
|
||||
write(state->mfd, writebuffer, state->writebufpos); state->writebufpos = 0; memset(writebuffer, 0, writebuffersize);
|
||||
}
|
||||
memcpy(writebuffer+state->writebufpos, buf, len); state->writebufpos += len;
|
||||
@ -388,19 +376,6 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
||||
if(p) *p = '\0';
|
||||
}
|
||||
|
||||
if(state->message_state == MSG_RECEIVED && sdata->ms_journal == 1 && sdata->ms_journal_dropped == 0){
|
||||
sdata->ms_journal_dropped = 1;
|
||||
sdata->journal_envelope_length -= len;
|
||||
state->writebufpos = 0; memset(writebuffer, 0, writebuffersize);
|
||||
memcpy(writebuffer+state->writebufpos, buf, strlen(buf)); state->writebufpos += strlen(buf);
|
||||
if(t == 2){
|
||||
memcpy(writebuffer+state->writebufpos, "\r\n", 2); state->writebufpos += 2;
|
||||
} else {
|
||||
memcpy(writebuffer+state->writebufpos, "\n", 1); state->writebufpos++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(state->is_1st_header == 1 && state->message_state == MSG_REFERENCES){
|
||||
if(strncasecmp(buf, "References:", 11) == 0) parse_reference(state, buf+11);
|
||||
|
@ -34,6 +34,5 @@ char *determine_attachment_type(char *filename, char *type);
|
||||
char *get_attachment_extractor_by_filename(char *filename);
|
||||
void parse_reference(struct _state *state, char *s);
|
||||
int base64_decode_attachment_buffer(char *p, int plen, unsigned char *b, int blen);
|
||||
void remove_trailing_journal_boundary(struct session_data *sdata, struct _state *state, char *writebuffer);
|
||||
|
||||
#endif /* _PARSER_H */
|
||||
|
@ -811,25 +811,3 @@ int base64_decode_attachment_buffer(char *p, int plen, unsigned char *b, int ble
|
||||
}
|
||||
|
||||
|
||||
void remove_trailing_journal_boundary(struct session_data *sdata, struct _state *state, char *writebuffer){
|
||||
int len;
|
||||
char *p;
|
||||
|
||||
p = strstr(writebuffer, state->boundaries->s);
|
||||
if(p){
|
||||
len = strlen(p);
|
||||
sdata->journal_bottom_length = len;
|
||||
state->writebufpos -= len;
|
||||
*p = '\0';
|
||||
p = strrchr(writebuffer, '\n');
|
||||
if(p){
|
||||
len = strlen(p);
|
||||
sdata->journal_bottom_length += len;
|
||||
state->writebufpos -= len;
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,8 +58,11 @@ class ControllerMessageBulkrestore extends Controller {
|
||||
if(count($rcpt) > 0) {
|
||||
$piler_id = $this->model_search_message->get_piler_id_by_id($id);
|
||||
|
||||
$msg = $this->model_search_message->get_raw_message($piler_id);
|
||||
$this->model_search_message->remove_journal($msg);
|
||||
|
||||
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt,
|
||||
"Received: by piler" . EOL . PILER_HEADER_FIELD . $id . EOL . $this->model_search_message->get_raw_message($piler_id) );
|
||||
"Received: by piler" . EOL . PILER_HEADER_FIELD . $id . EOL . $msg );
|
||||
|
||||
if($x == 1) { $this->data['restored']++; }
|
||||
}
|
||||
|
@ -41,10 +41,9 @@ class ControllerMessageDownload extends Controller {
|
||||
header("Content-Transfer-Encoding: binary\n");
|
||||
|
||||
|
||||
print $this->model_search_message->get_raw_message($this->data['piler_id']);
|
||||
exit;
|
||||
|
||||
$this->render();
|
||||
$msg = $this->model_search_message->get_raw_message($this->data['piler_id']);
|
||||
$this->model_search_message->remove_journal($msg);
|
||||
print $msg;
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,8 +58,11 @@ class ControllerMessageRestore extends Controller {
|
||||
|
||||
$this->data['piler_id'] = $this->model_search_message->get_piler_id_by_id($this->data['id']);
|
||||
|
||||
$msg = $this->model_search_message->get_raw_message($this->data['piler_id']);
|
||||
$this->model_search_message->remove_journal($msg);
|
||||
|
||||
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt,
|
||||
"Received: by piler" . EOL . PILER_HEADER_FIELD . $this->data['id'] . EOL . $this->model_search_message->get_raw_message($this->data['piler_id']) );
|
||||
"Received: by piler" . EOL . PILER_HEADER_FIELD . $this->data['id'] . EOL . $msg );
|
||||
|
||||
if($x == 1) { $this->data['data'] = $this->data['text_restored']; }
|
||||
}
|
||||
|
@ -68,6 +68,8 @@ class ModelSearchMessage extends Model {
|
||||
|
||||
$msg = $this->get_raw_message($id);
|
||||
|
||||
$this->remove_journal($msg);
|
||||
|
||||
$pos = strpos($msg, "\n\r\n");
|
||||
if($pos == false) {
|
||||
$pos = strpos($msg, "\n\n");
|
||||
@ -85,6 +87,38 @@ class ModelSearchMessage extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function remove_journal(&$msg = '') {
|
||||
$p = $q = '';
|
||||
$boundary = '';
|
||||
|
||||
$hdr = substr($msg, 0, 4096);
|
||||
|
||||
$s = preg_split("/\n/", $hdr);
|
||||
while(list($k, $v) = each($s)) {
|
||||
if(preg_match("/boundary\s{0,}=\s{0,}\"{0,}([\w\_\-\@\.]+)\"{0,}/i", $v, $m)) {
|
||||
if(isset($m[1])) { $boundary = $m[1]; break; }
|
||||
}
|
||||
}
|
||||
|
||||
$p = strstr($msg, "\nX-MS-Journal-Report:");
|
||||
if($p) {
|
||||
$msg = '';
|
||||
$q = strstr($p, "Received: from");
|
||||
if($q) {
|
||||
$p = '';
|
||||
$msg = $q;
|
||||
$q = '';
|
||||
}
|
||||
else {
|
||||
$msg = $p;
|
||||
$p = '';
|
||||
}
|
||||
}
|
||||
|
||||
$msg = substr($msg, 0, strlen($msg) - strlen($boundary) - 6);
|
||||
}
|
||||
|
||||
|
||||
public function extract_message($id = '') {
|
||||
$header = "";
|
||||
$body_chunk = "";
|
||||
@ -102,6 +136,8 @@ class ModelSearchMessage extends Model {
|
||||
|
||||
$msg = $this->get_raw_message($id);
|
||||
|
||||
$this->remove_journal($msg);
|
||||
|
||||
$a = explode("\n", $msg); $msg = "";
|
||||
|
||||
while(list($k, $l) = each($a)){
|
||||
|
Loading…
Reference in New Issue
Block a user