diff --git a/Rocksolid_Light/rslight/scripts/interBBS_mail.php b/Rocksolid_Light/rslight/scripts/interBBS_mail.php index 6c173a7..5f7f891 100644 --- a/Rocksolid_Light/rslight/scripts/interBBS_mail.php +++ b/Rocksolid_Light/rslight/scripts/interBBS_mail.php @@ -104,9 +104,11 @@ $gnupg_validity = array( echo "THE DOMAINS MATCH. OK TO IMPORT MESSAGE\n"; echo $plaintext; print_r($inspect); - + $mail_from = $inspect['bbsmail_sender'].'@'.$inspect['bbsmail_domain']; - $rcpt_to = $inspect['bbsmail_recipient']; + $info = preg_split('/@/', $inspect['bbsmail_recipient'], 2); + $rcpt_to = $info[0]; + $date = strtotime($inspect['bbsmail_date']); if(!isset($inspect['bbsmail_sender']) || !isset($inspect['bbsmail_recipient']) || !isset($inspect['bbsmail_sender']) || !isset($inspect['bbsmail_body'])) { @@ -152,6 +154,7 @@ if($do_mail_update == true) { function import_user_message($from, $rcpt, $date, $subject, $message) { global $config_dir, $spooldir; + if(($to = get_config_value('aliases.conf', strtolower($rcpt))) == false) { $to = strtolower($rcpt); } @@ -252,6 +255,7 @@ function get_key_from_message($res, $inspect) { function inspect_bbsmail($res, $plaintext) { $bbsmail_header = 0; $bbsmail_body = 0; + $message_body = 0; $plaintext = explode("\n", $plaintext); foreach($plaintext as $line) { if(strpos($line, '@@BEGIN BBSMAIL HEADERS') !== false) { @@ -293,6 +297,15 @@ function inspect_bbsmail($res, $plaintext) { continue; } if($bbsmail_body == 1) { + if(strpos($line, '@@END BBSMAIL BODY') !== false) { + break; + } + + if($message_body == 1) { + $return_data['bbsmail_body'].=$line."\n"; + continue; + } + if(strpos($line, 'Sender: ') !== false) { $bbsmail = explode("Sender: ", $line); $return_data['bbsmail_sender'] = trim($bbsmail[1]); @@ -311,16 +324,14 @@ function inspect_bbsmail($res, $plaintext) { } else { if(strpos($line, 'Body: ') !== false) { $bbsmail = explode("Body: ", $line); - $return_data['bbsmail_body'] = trim($bbsmail[1]); + $return_data['bbsmail_body'] = $bbsmail[1]."\n"; + $message_body = 1; } } } } } } - if(strpos($line, '@@END BBSMAIL BODY') !== false) { - continue; - } if(trim($line) == '.') { $line = ' '; } @@ -328,7 +339,6 @@ function inspect_bbsmail($res, $plaintext) { if(!isset($return_data['body'])) { $line = ltrim($line); } - // $return_data['body'].= $line; } } return($return_data); diff --git a/Rocksolid_Light/spoolnews/mail.php b/Rocksolid_Light/spoolnews/mail.php index eb92bd7..7a44f28 100644 --- a/Rocksolid_Light/spoolnews/mail.php +++ b/Rocksolid_Light/spoolnews/mail.php @@ -3,6 +3,7 @@ session_start(); include "config.inc.php"; include "newsportal.php"; +include $config_dir."/gpg.conf"; if(isset($_COOKIE['tzo'])) { $offset=$_COOKIE['tzo']; @@ -194,10 +195,13 @@ echo ''; $found = 0; foreach($userlist as $user) { if(trim($to) == trim($user)) { - $found = 1; - break; + $found = 1; } } +// Handle unknown domains here also (no pgp key for domain) + if(strpos($to, '@') !== false) { + $found = 1; + } if($found == 0) { echo 'User not found: '.$to; } else { @@ -209,13 +213,16 @@ echo ''; $date = time(); $message = $_POST['message']; $msgid = '<'.md5(strtolower($to).strtolower($from).strtolower($subject).strtolower($message)).'>'; - $sql = 'INSERT INTO messages(msgid, mail_from, rcpt_to, rcpt_target, date, subject, message, from_hide, to_hide, mail_viewed, rcpt_viewed) VALUES(?,?,?,?,?,?,?,?,?,?,?)'; + $sql = 'INSERT OR IGNORE INTO messages(msgid, mail_from, rcpt_to, rcpt_target, date, subject, message, from_hide, to_hide, mail_viewed, rcpt_viewed) VALUES(?,?,?,?,?,?,?,?,?,?,?)'; $stmt = $dbh->prepare($sql); // For possible future use $target = "local"; $mail_viewed = "true"; $rcpt_viewed = null; $q = $stmt->execute([$msgid, $from, $to, $target, $date, $subject, $message, null, null, $mail_viewed, $rcpt_viewed]); + + send_external_mail($from, $to, $date, $subject, $message); + if ($q) { echo 'Message sent.'; }else @@ -310,4 +317,88 @@ echo ''; } echo '
'; include "tail.inc"; + + function send_external_mail($sender, $recipient, $date, $subject, $message) { + global $rslight_gpg, $config_name, $spooldir, $rslight_version; + putenv("GNUPGHOME=".$rslight_gpg['gnupghome']); + $res = gnupg_init(); + + $cwd = getcwd(); + $keydir = preg_replace('/spoolnews/','pubkey/',$cwd); + $key_location = "/pubkey/server_pubkey.txt"; + $signing_key = trim(file_get_contents($keydir.'/server_fingerprint.txt')); + $fingerprint_clean = preg_replace('/\ /', '', $signing_key); + gnupg_addsignkey($res,$fingerprint_clean); + gnupg_adddecryptkey($res,$fingerprint_clean, ''); + + // Get target domain + $info = preg_split('/@/', $recipient, 2); + $target['domain'] = $info[1]; + $keyinfo = gnupg_keyinfo($res, $target['domain']); + $target['fingerprint'] = $keyinfo[0]['subkeys'][0]['fingerprint']; + $encrypt_to_key = $target['fingerprint']; + gnupg_addencryptkey($res,$encrypt_to_key); + + $mydate = gmdate("D, d M Y H:i:s \U\T\C",$date); + + $outgoing_dir = $spooldir.'/'.$config_name.'/outgoing'; + if(!is_dir($outgoing_dir)) { + mkdir($outgoing_dir, 0700, true); + } + $domain = $rslight_gpg['domain_name']; + $organization = $CONFIG['organization']; + $from = $rslight_gpg['from_email']; + $contact = $rslight_gpg['contact']; + + $outgoing_file = tempnam($outgoing_dir, 'bbsmail-'); + + $start="@@BEGIN BBSMAIL HEADERS"; + $begin="@@BEGIN BBSMAIL BODY"; + $end="@@END BBSMAIL BODY"; + + $body=''; + $body.="You may use this to import MAIL for $domain.\n\n"; + + $body.="This message was signed using the following key:\n"; + $body.="$signing_key\n\n"; + + $body.="The GPG key needed to verify the signature of messages\n"; + $body.="issued by $from is available at:\n"; + $body.="$domain$key_location\n\n"; + + $body.="For information contact $contact.\n\n"; + + $body.=$start."\n"; + $body.=' Version: '.$rslight_version."\n"; + $body.=' From: '.$from."\n"; + $hashtail = hash('crc32', $domain.$organization.$sender.$rslight_gpg['nntp_group']); + $thishash = hash('crc32', $message.$hashtail).hash('crc32', $signing_key); + $body.=" Notice-ID: ".$thishash."\n"; + $body.=" Key: ".$signing_key."\n"; + $body.=" Location: ".$domain.$key_location."\n"; + $body.=" Domain: ".$domain."\n"; + + $body.=$begin."\n"; + $body.=" Sender: ".$sender."\n"; + $body.=" Recipient: ".$recipient."\n"; + $body.=" Date: ".$mydate."\n"; + $body.=" Subject: ".$subject."\n"; + $body.=" Body: ".$message."\n"; + $body.=$end."\n"; + + $header=''; + $header.="From: $from\n"; + $header.="Newsgroups: ".$rslight_gpg['nntp_group']."\n"; + $header.="Subject: @@RSL BBSMAIL notice ".$thishash."\n"; + $header.="Date: ".$mydate."\n"; + $header.="Message-ID: <$thishash@$domain>\n"; + $header.="Content-Type: text/plain; charset=utf-8; format=flowed\n"; + $header.="Content-Transfer-Encoding: 8bit\n"; + $header.="Organization: $organization\n\n"; + + $encrypted_text = gnupg_encryptsign($res, $body); + + file_put_contents($outgoing_file, $header.$encrypted_text); + echo "Posted <".$thishash."@".$domain.">\n\n"; + } ?>