More UTF8 message processing fixes, specifically related to tagline/tearline/origin processing
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 39s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m46s
Create Docker Image / Final Docker Image Manifest (push) Successful in 12s

This commit is contained in:
Deon George 2024-06-05 21:57:16 +10:00
parent 6b1cb8cd78
commit 742f0cd015
6 changed files with 84 additions and 22 deletions

View File

@ -34,7 +34,7 @@ class MessageProcess implements ShouldQueue
public function __construct(Echomail|Netmail $mo,bool $skipbot=FALSE)
{
// @todo We need to serialize this model here, because laravel has an error unserializing it (Model Not Found)
$this->mo = serialize($mo);
$this->mo = utf8_encode(serialize($mo));
$this->skipbot = $skipbot;
}
@ -57,7 +57,7 @@ class MessageProcess implements ShouldQueue
*/
public function handle()
{
$this->mo = unserialize($this->mo);
$this->mo = unserialize(utf8_decode($this->mo));
// Load our details
$ftns = our_address();

View File

@ -35,9 +35,6 @@ final class Echomail extends Model implements Packet
'to' => UTF8StringOrNull::class,
'from' => UTF8StringOrNull::class,
'subject' => UTF8StringOrNull::class,
'origin' => UTF8StringOrNull::class,
'tearline' => UTF8StringOrNull::class,
'tagline' => UTF8StringOrNull::class,
'datetime' => 'datetime:Y-m-d H:i:s',
'kludges' => CollectionOrNull::class,
'msg' => CompressedStringOrNull::class,
@ -123,18 +120,46 @@ final class Echomail extends Model implements Packet
if (isset($model->errors) && $model->errors->count())
throw new \Exception('Cannot save, validation errors exist');
if ($model->set->has('set_tagline'))
$model->tagline_id = Tagline::firstOrCreate(['value'=>$model->set_tagline])->id;
if ($model->set->has('set_tagline')) {
$x = Tagline::where('value',utf8_encode($model->set_tagline))->single();
if ($model->set->has('set_tearline'))
$model->tearline_id = Tearline::firstOrCreate(['value'=>$model->set_tearline])->id;
if (! $x) {
$x = new Tagline;
$x->value = $model->set_tagline;
$x->save();
}
$model->tagline_id = $x->id;
}
if ($model->set->has('set_tearline')) {
$x = Tearline::where('value',utf8_encode($model->set_tearline))->single();
if (! $x) {
$x = new Tearline;
$x->value = $model->set_tearline;
$x->save();
}
$model->tearline_id = $x->id;
}
if ($model->set->has('set_origin')) {
// Make sure our origin contains our FTN
$m = [];
if ((preg_match('#^(.*)\s+\(([0-9]+:[0-9]+/[0-9]+.*)\)+\s*$#',$model->set_origin,$m))
&& (Address::findFTN(sprintf('%s@%s',$m[2],$model->fftn->domain->name))?->id === $model->fftn_id))
$model->origin_id = Origin::firstOrCreate(['value'=>$m[1]])->id;
{
$x = Origin::where('value',utf8_encode($m[1]))->single();
if (! $x) {
$x = new Origin;
$x->value = $m[1];
$x->save();
}
$model->origin_id = $x->id;
}
}
// If we can rebuild the message content, then we can do away with msg_src

View File

@ -35,9 +35,6 @@ final class Netmail extends Model implements Packet
'to' => UTF8StringOrNull::class,
'from' => UTF8StringOrNull::class,
'subject' => UTF8StringOrNull::class,
'origin' => UTF8StringOrNull::class,
'tearline' => UTF8StringOrNull::class,
'tagline' => UTF8StringOrNull::class,
'datetime' => 'datetime:Y-m-d H:i:s',
'kludges' => CollectionOrNull::class,
'msg' => CompressedStringOrNull::class,
@ -116,18 +113,46 @@ final class Netmail extends Model implements Packet
if (isset($model->errors) && $model->errors->count())
throw new \Exception('Cannot save, validation errors exist');
if ($model->set->has('set_tagline'))
$model->tagline_id = Tagline::firstOrCreate(['value'=>$model->set_tagline])->id;
if ($model->set->has('set_tagline')) {
$x = Tagline::where('value',utf8_encode($model->set_tagline))->single();
if ($model->set->has('set_tearline'))
$model->tearline_id = Tearline::firstOrCreate(['value'=>$model->set_tearline])->id;
if (! $x) {
$x = new Tagline;
$x->value = $model->set_tagline;
$x->save();
}
$model->tagline_id = $x->id;
}
if ($model->set->has('set_tearline')) {
$x = Tearline::where('value',utf8_encode($model->set_tearline))->single();
if (! $x) {
$x = new Tearline;
$x->value = $model->set_tearline;
$x->save();
}
$model->tearline_id = $x->id;
}
if ($model->set->has('set_origin')) {
// Make sure our origin contains our FTN
$m = [];
if ((preg_match('#^(.*)\s+\(([0-9]+:[0-9]+/[0-9]+.*)\)+\s*$#',$model->set_origin,$m))
&& (Address::findFTN($m[2])->id === $model->fftn_id))
$model->origin_id = Origin::firstOrCreate(['value'=>$m[1]])->id;
&& (Address::findFTN(sprintf('%s@%s',$m[2],$model->fftn->domain->name))?->id === $model->fftn_id))
{
$x = Origin::where('value',utf8_encode($m[1]))->single();
if (! $x) {
$x = new Origin;
$x->value = $m[1];
$x->save();
}
$model->origin_id = $x->id;
}
}
// If we can rebuild the message content, then we can do away with msg_src

View File

@ -5,13 +5,17 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Casts\UTF8StringOrNull;
class Origin extends Model
{
//use HasFactory;
public const UPDATED_AT = NULL;
protected $fillable = ['value'];
protected $casts = [
'value' => UTF8StringOrNull::class,
];
public function complete(Address $o): string
{

View File

@ -5,13 +5,17 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Casts\UTF8StringOrNull;
class Tagline extends Model
{
//use HasFactory;
public const UPDATED_AT = NULL;
protected $fillable = ['value'];
protected $casts = [
'value' => UTF8StringOrNull::class,
];
public function complete(): string
{

View File

@ -5,13 +5,17 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Casts\UTF8StringOrNull;
class Tearline extends Model
{
//use HasFactory;
public const UPDATED_AT = NULL;
protected $fillable = ['value'];
protected $casts = [
'value' => UTF8StringOrNull::class,
];
public function complete(): string
{