From c8a2affbfa8f7fad6f4e4306e4bff5f59d799dc6 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 4 Aug 2023 22:06:29 +1000 Subject: [PATCH] Fix for when packets have a kludge after the origin line, and now capturing taglines. Updated testing configuration --- .env.example | 2 +- .env.testing | 18 +++-- app/Classes/FTN/Message.php | 65 ++++++++++++++---- phpunit.xml | 55 ++++++++------- resources/views/pkt.blade.php | 8 +++ tests/Feature/PacketTest.php | 51 ++++++++++++++ .../data/test_msg_with_soh_in_origin.pkt | Bin 0 -> 7228 bytes 7 files changed, 152 insertions(+), 47 deletions(-) create mode 100644 tests/Feature/data/test_msg_with_soh_in_origin.pkt diff --git a/.env.example b/.env.example index cacb795..ee9b45c 100644 --- a/.env.example +++ b/.env.example @@ -29,7 +29,7 @@ REDIS_PASSWORD= REDIS_PORT=6379 MAIL_DRIVER=smtp -MAIL_HOST=mail.leenooks.lan +MAIL_HOST=mail.dege.lan MAIL_PORT=25 MAIL_USERNAME= MAIL_PASSWORD= diff --git a/.env.testing b/.env.testing index 6d825f8..bca7f1d 100644 --- a/.env.testing +++ b/.env.testing @@ -2,7 +2,8 @@ APP_NAME="Clearing Houz Testing" APP_ENV=testing APP_KEY=base64:FiMSvv4J7jDfy6W/sHrQ9YImuUYaxynYCcXQJwp/6Tc= APP_DEBUG=true -#APP_URL=http://localhost +APP_URL=http://localhost +APP_TIMEZONE=Australia/Melbourne LOG_CHANNEL=stderr LOG_LEVEL=debug @@ -14,10 +15,6 @@ DB_DATABASE=test DB_USERNAME=test DB_PASSWORD=test -DB_MONGO_HOST=mongo -DB_MONGO_USERNAME=mongo -DB_MONGO_PASSWORD=password - BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync @@ -43,3 +40,14 @@ PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +FIDO_DIR=fido +FIDO_PACKET_KEEP=true + +FILESYSTEM_DISK=s3 +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_BUCKET= +AWS_ENDPOINT= +AWS_DEFAULT_REGION= +AWS_USE_PATH_STYLE_ENDPOINT= diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index a34cc61..6ecdee0 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -212,8 +212,8 @@ class Message extends FTNBase $this->echoarea = ''; $this->intl = ''; - $this->tearline = ''; - $this->tagline = ''; + $this->tearline = NULL; + $this->tagline = NULL; $this->origin = ''; $this->tzutc = 0; @@ -733,7 +733,9 @@ class Message extends FTNBase // Split out each line $result = collect(explode("\r",$message))->filter(); - foreach ($result as $v) { + while ($result->count()) { + $v = $result->shift(); + foreach ($this->_kludge as $a => $b) { if ($t = $this->kludge($b,$v)) { $this->kludge->put($a,$t); @@ -747,8 +749,16 @@ class Message extends FTNBase elseif ($t = $this->kludge('PATH: ', $v)) $this->path->push($t); - elseif ($t = $this->kludge(' \* Origin: ',$v)) - $this->origin = $t; + elseif ($t = $this->kludge(' \* Origin: ',$v)) { + // Check in case there is a kludge that starts with SOH + if ($soh=strpos($t,"\x01")) { + $this->origin = substr($t,0,$soh); + $result->push(substr($t,$soh+1)); + + } else { + $this->origin = $t; + } + } // We got unknown Kludge lines in the origin else @@ -816,38 +826,56 @@ class Message extends FTNBase $this->message = ''; $this->message_src = ''; $msgpos = 0; + $haveOrigin = FALSE; - foreach ($result as $kl) { + while ($result->count()) { // $kl is our line starting with a \x01 kludge delimiter + $kl = $result->shift(); // Search for \r - if that is the end of the line, then its a kludge $retpos = strpos($kl,"\r"); $msgpos += 1+strlen($kl); // SOH+text $t = ''; - // If there are is a return in this middle of this line, that means the text message starts after the return - // If our message has started, then we'll assume the binary is part of the message. - if (strlen($this->message) || ($retpos !== strlen($kl)-1)) { + // If there is a return in this middle of this line, that means the text message starts after the return, + // ie: SOH+text\rmessage - // If there was no return, its part of the message. + // Just in case we already parsed this as part of our message, we'll continue, since its probably a + // binary message with a SOH inside it. + if (strlen($this->message) || ($retpos !== strlen($kl)-1)) { + // If there was no return, its part of the message, so we need to add back the SOH. if ($retpos === FALSE) { $this->message .= "\x01".$kl; continue; } - // Anything after the origin line is also kludge data. - if ($originpos = strrpos($kl,"\r * Origin: ")) { + // Check if this has the origin line. Anything before is the message, anything after the origin + // line is also kludge data. + if ($originpos=strrpos($kl,"\r * Origin: ")) { + // Anything after the return (from the kludge) is a message. if (! $this->message) { $this->message .= substr($kl,$retpos+1,$originpos-$retpos-1); + // But if we are already sourcing a message, then its part of it message. } else { $this->message .= "\x01".substr($kl,0,$originpos); $retpos = 0; } + // See if we have a tagline + if ($tl=strrpos($kl,"\r... ")) { + $tlr = strpos(substr($kl,$tl+6),"\r"); + + $this->tagline = substr($kl,$tl+5,$tlr); + } + + // Message is finished, now we are parsing origin data (and more kludges) $this->parseOrigin(substr($kl,$originpos+1)); + $haveOrigin = TRUE; + + // Our message source (for resending, is everything up to the end of the origin line. $this->message_src = substr($message, 0, $msgpos - (1+strlen($kl)) + $originpos + 12 + strlen($this->origin) + 1); $kl = substr($kl,0,$retpos); @@ -876,11 +904,18 @@ class Message extends FTNBase } // The message is the rest? + // Netmails dont generally have an origin line } elseif (strlen($kl) > $retpos+1) { - // Since netmail doesnt have an origin - our source: - $this->message .= substr($kl,$retpos+1); - $this->message_src = substr($message, 0, $msgpos); + // We still have some text to process, add it to the list + if ($haveOrigin && ($retpos+1 < strlen($kl))) { + $result->push(substr($kl,$retpos+1)); + + // If this was the overflow from echomail, then our message_src would be defined, and thus its not part of the message + } else { + $this->message .= substr($kl,$retpos+1); + $this->message_src = substr($message, 0, $msgpos); + } $kl = substr($kl,0,$retpos); } diff --git a/phpunit.xml b/phpunit.xml index c273583..f112c0c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,28 +1,31 @@ - - - - ./tests/Unit - - - ./tests/Feature - - - - - - - - - - - - - - - - - ./app - - + + + + tests/Unit + + + tests/Feature + + + + + app + + + + + + + + + + + + + diff --git a/resources/views/pkt.blade.php b/resources/views/pkt.blade.php index 726e900..2719533 100644 --- a/resources/views/pkt.blade.php +++ b/resources/views/pkt.blade.php @@ -119,6 +119,14 @@ + @if($msg->tagline) +
+
+ TAGLINE:
{{ $msg->tagline }} +
+
+ @endif + @if($msg->isNetmail())
diff --git a/tests/Feature/PacketTest.php b/tests/Feature/PacketTest.php index b0ba45a..dc5b836 100644 --- a/tests/Feature/PacketTest.php +++ b/tests/Feature/PacketTest.php @@ -201,4 +201,55 @@ class PacketTest extends TestCase $this->assertTrue($messages); } } + + public function test_soh_in_origin() + { + // This packet has a SOHSOH sequence + $f = new File(__DIR__.'/data/test_msg_with_soh_in_origin.pkt'); + + foreach ($f as $packet) { + $pkt = Packet::process($packet,$f->itemName(),$f->itemSize(),NULL,FALSE); + + $this->assertEquals(9,$pkt->count()); + + $messages = FALSE; + $c = 0; + foreach ($pkt as $msg) { + $c++; + $messages = TRUE; + + $this->assertNotTrue($msg->isNetmail()); + + switch ($c) { + case 1: + $this->assertSame('3:712/886 220da89f',$msg->msgid); + $this->assertSame('9f5544bea46ef57a45f561b9e07dd71e',md5($msg->message)); + $this->assertSame('9bf4b8c348ac235cc218577abf7140af',md5($msg->message_src)); + $this->assertCount(3,$msg->rogue_path); + $this->assertCount(16,$msg->rogue_seenby); + $this->assertContains('633/0 267 280 281 408 410 412 509 509 640/1384 712/114 550 620 848',$msg->seenby); + $this->assertContains('712/886 848 633/280',$msg->path); + $this->assertCount(2,$msg->seenby); + $this->assertCount(0,$msg->unknown); + break; + + case 4: + $this->assertSame('',$msg->msgid); + $this->assertSame('b975057002def556c5a9497aacd000fb',md5($msg->message)); + $this->assertSame('c90dd234d2aa029af22c453a25b79a4e',md5($msg->message_src)); + $this->assertCount(3,$msg->rogue_path); + $this->assertCount(19,$msg->rogue_seenby); + $this->assertContains('633/267 280 281 384 408 410 412 418 420 509 509 712/848 770/1 100 330',$msg->seenby); + $this->assertContains('772/210 770/1 633/280',$msg->path); + $this->assertCount(2,$msg->seenby); + $this->assertCount(0,$msg->unknown); + + default: + continue 2; + } + } + + $this->assertTrue($messages); + } + } } diff --git a/tests/Feature/data/test_msg_with_soh_in_origin.pkt b/tests/Feature/data/test_msg_with_soh_in_origin.pkt new file mode 100644 index 0000000000000000000000000000000000000000..d1bbe8f538e02b4820f485aca9df581ea720797d GIT binary patch literal 7228 zcmeHMU2o&Y6_qvxfSSmrp+}{G#xi!mkST zLZR@YFn=+B@y{X-)4xv&pYZ?UuYXy@QF@%7e^K}h&+@(e)2dKQL}b;8tg2_%y>hK^ zCX%5Dg&Y-LOB~8*EW*Nt^r)*R)K!y0PcUW zCFu~~KHK6eeHFzCg(6WpoT)(4MEF-S*@p&ASmN;C~M zCOpLwvC=RgUyMe01Z%%@Ly3-bM8CJn@Woh%nAcoS$=B0Sz@~g1hSE=s2^wiw$Y-`q z{YZ~_c%HU~eN2ge<<}R>%^jLfEAzxQKNOOlCV_&v+zh;tEt!pF17VY8yiJ(2p0Ou+ zVu@x;;##W!cj089;zWelKz}Hr0sLhc-E>Yfo|rGAL|_x;4K9bcjO|-mJa(Dyx?OSV zAzn&)zC?6lL~<<0JuGXWc@CIdd#HH1sq29m$)`nclzM?ZOs9vrLo(|*hAunQ*O7ts zN(sw`(ZH?n1U5-eVwy>svC}aQ&PIAV7*Y>d%AAE^$Kpz^FFD&Bb*+-Q!86JiP9oit zK+NgKDc~t+l1_4l6RErJR%q;Syj~f`&JK?5g6nz_U1Xb9eb;pGq0I{sPvDDaPUmXZ zv9}C*N$p4tROr#m{a`+^D+(3&D(I?GCIxX+0Oo-JmO$B$*xohA&sv^u3013 zGV!&kY}V6n#Wi;=r{)sJvt_wdE}K-bO{%%IJ6nrjuU2ulQ9N&SkG=E>W&qro4#vy@ zDqEqb8XZa>907`QJQEaEDPS)O=VCgdV=+&3SZELFhU||crs^^=@f;D=u30sEWw&=r zOqK&;`kFV%A4>m(mjhL$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