From ab7f661800461d72edb1d981c8daf7a871a75593 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 11 Sep 2023 21:52:48 +1000 Subject: [PATCH] Use FTN from origin as our primary address, and msgid if the origin line doesnt have one --- app/Classes/FTN/Message.php | 40 +++++++------------------------------ 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 0f4c0d3..bfa4267 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -786,6 +786,7 @@ class Message extends FTNBase * @param Collection $via * @param Collection $rogue * @return Collection + * @throws \Exception */ private function parseVia(Collection $via,Collection &$rogue): Collection { @@ -891,34 +892,9 @@ class Message extends FTNBase $this->message_src = substr($message, 0, $msgpos - (1+strlen($kl)) + $originpos + 12 + strlen($this->origin) + 1); $kl = substr($kl,0,$retpos); - // If this is netmail, the FQFA will have been set by the INTL line, we can skip the rest of this - $matches = []; - - // Capture the fully qualified 4D name from the Origin Line - it tells us the ZONE. - preg_match('/^.*\((.*)\)$/',$this->origin,$matches); - - // Double check we have an address in the origin line - if (! Arr::get($matches,1)) { - Log::error(sprintf('%s:! Origin line doesnt have an address',self::LOGKEY)); - - } else { - // Double check, our src and origin match - try { - $this->src = Address::parseFTN($matches[1]); - } catch (\Exception $e) { - Log::error(sprintf('%s:! Origin line address [%s] is invalid [%s]',self::LOGKEY,$this->origin,$e->getMessage())); - } - } - - // We'll double check our FTN - if ($this->isNetmail() && (($this->src['n'] !== $this->fn) || ($this->src['f'] !== $this->ff))) { - Log::error(sprintf('%s:! FTN [%s] doesnt match message header',self::LOGKEY,$matches[1]),['ftn'=>$this->src,'fn'=>$this->fn,'ff'=>$this->ff]); - } - // The message is the rest? // Netmails dont generally have an origin line } elseif (strlen($kl) > $retpos+1) { - // We still have some text to process, add it to the list if ($haveOrigin && ($retpos+1 < strlen($kl))) { $result->push(substr($kl,$retpos+1)); @@ -936,12 +912,11 @@ class Message extends FTNBase continue; } - foreach ($this->_kludge as $a => $b) { + foreach ($this->_kludge as $a => $b) if ($t = $this->kludge($b,$kl)) { $this->kludge->put($a,$t); break; } - } // There is more text. if ($t) @@ -1011,20 +986,19 @@ class Message extends FTNBase // Work out our zone/point // http://ftsc.org/docs/fsc-0068.001 - // MSGID should be the basis of the source, we'll overwrite our src from origin if we have it + // MSGID should be the basis of the source, if it cannot be obtained from the origin // If the message was gated, we'll use the gateid $m = []; - if (($this->msgid || $this->gateid) && preg_match('#([0-9]+:[0-9]+/[0-9]+)?\.?([0-9]+)?(\.[0-9]+)?@?([A-Za-z-_~]+)?\ +#',$this->gateid ?: $this->msgid,$m)) { + if ($this->origin && preg_match('#\(([0-9]+:[0-9]+/[0-9]+)?\.?([0-9]+)?@?([A-Za-z-_~]+)?\)$#',$this->origin,$m)) { + $this->src = Address::parseFTN($m[1].((isset($m[2]) && $m[2] != '') ? '.'.$m[2] : '').(isset($m[3]) ? '@'.$m[3] : '')); + + } elseif (($this->msgid || $this->gateid) && preg_match('#([0-9]+:[0-9]+/[0-9]+)?\.?([0-9]+)?(\.[0-9]+)?@?([A-Za-z-_~]+)?\ +#',$this->gateid ?: $this->msgid,$m)) { try { $this->src = Address::parseFTN($m[1].((isset($m[2]) && $m[2] != '') ? '.'.$m[2] : '').(isset($m[4]) ? '@'.$m[4] : '')); } catch (\Exception $e) { Log::error(sprintf('%s:! MSGID [%s] address is invalid [%s]',self::LOGKEY,$this->msgid,$e->getMessage())); } - // Without a MSGID, get our domain from the origin - } elseif ($this->origin && preg_match('#\(([0-9]+:[0-9]+/[0-9]+)?\.?([0-9]+)?@?([A-Za-z-_~]+)?\)$#',$this->origin,$m)) { - $this->src = Address::parseFTN($m[1].((isset($m[2]) && $m[2] != '') ? '.'.$m[2] : '').(isset($m[3]) ? '@'.$m[3] : '')); - // Otherwise get it from our zone object and packet header } elseif ($this->zone) { $this->src = Address::parseFTN(sprintf('%d:%d/%d.%d@%s',$this->zone->zone_id,$this->fn,$this->ff,$this->fp,$this->zone->domain->name));