$msg_p->pmsg_opt |= 64;
     } else {
         if ($_POST['forward']) {
             $msg_p->ref_msg_id = 'F' . $_POST['forward'];
         } else {
             $msg_p->ref_msg_id = null;
             $msg_p->pmsg_opt |= 32;
         }
     }
     $msg_p->add();
 } else {
     $msg_p->id = (int) $_POST['msg_id'];
     $msg_p->sync();
 }
 if (isset($attach_list)) {
     attach_finalize($attach_list, $msg_p->id, 1);
     /* we need to add attachments to all copies of the message */
     if (!isset($_POST['btn_draft'])) {
         $c = uq('SELECT id, original_name, mime_type, fsize FROM phpgw_fud_attach WHERE message_id=' . $msg_p->id . ' AND attach_opt=1');
         while ($r = db_rowarr($c)) {
             $atl[$r[0]] = "'" . addslashes($r[1]) . "', " . $r[2] . ", " . $r[3];
         }
         if (isset($atl)) {
             foreach ($GLOBALS['send_to_array'] as $mid) {
                 foreach ($atl as $k => $v) {
                     $aid = db_qid('INSERT INTO phpgw_fud_attach (owner, attach_opt, message_id, original_name, mime_type, fsize, location) VALUES(' . $mid[0] . ', 1, ' . $mid[1] . ', ' . $v . ', \'\')');
                     $aidl[] = $aid;
                     copy($FILE_STORE . $k . '.atch', $FILE_STORE . $aid . '.atch');
                     @chmod($FILE_STORE . $aid . '.atch', $FUD_OPT_2 & 8388608 ? 0600 : 0666);
                 }
             }
$msg_post->post_stamp = !empty($emsg->headers['date']) ? strtotime($emsg->headers['date']) : 0;
if ($msg_post->post_stamp < 1 || $msg_post->post_stamp > __request_timestamp__) {
    mlist_error_log("Invalid Date", $emsg->raw_msg);
    if (($p = strpos($emsg->headers['received'], '; ')) !== false) {
        $p += 2;
        $msg_post->post_stamp = strtotime(substr($emsg->headers['received'], $p, strpos($emsg->headers['received'], '00 ', $p) + 2 - $p));
    }
    if ($msg_post->post_stamp < 1 || $msg_post->post_stamp > __request_timestamp__) {
        $msg_post->post_stamp = __request_timestamp__;
    }
}
// try to determine whether this message is a reply or a new thread
list($msg_post->reply_to, $msg_post->thread_id) = get_fud_reply_id($mlist->mlist_opt & 32, $frm->id, $msg_post->subject, $emsg->reply_to_msg_id);
$msg_post->add($frm->id, $frm->message_threshold, 0, 0, false);
// Handle File Attachments
if ($mlist->mlist_opt & 8 && isset($emsg->attachments) && is_array($emsg->attachments)) {
    foreach ($emsg->attachments as $key => $val) {
        $tmpfname = tempnam($TMP, 'FUDf_');
        $fp = fopen($tmpfname, 'wb');
        fwrite($fp, $val);
        fclose($fp);
        $id = attach_add(array('name' => $key, 'size' => strlen($val), 'tmp_name' => $tmpfname), $msg_post->poster_id, 0, 1);
        $attach_list[$id] = $id;
    }
    if (isset($attach_list)) {
        attach_finalize($attach_list, $msg_post->id);
    }
}
if (!($mlist->mlist_opt & 1)) {
    $msg_post->approve($msg_post->id, true);
}