diff --git a/app/Jobs/MessageProcess.php b/app/Jobs/MessageProcess.php index cba05a0..37342cc 100644 --- a/app/Jobs/MessageProcess.php +++ b/app/Jobs/MessageProcess.php @@ -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(); diff --git a/app/Models/Echomail.php b/app/Models/Echomail.php index f8e9d30..ee50351 100644 --- a/app/Models/Echomail.php +++ b/app/Models/Echomail.php @@ -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 diff --git a/app/Models/Netmail.php b/app/Models/Netmail.php index 96f178b..06ee9a0 100644 --- a/app/Models/Netmail.php +++ b/app/Models/Netmail.php @@ -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 diff --git a/app/Models/Origin.php b/app/Models/Origin.php index 017a270..2927b1d 100644 --- a/app/Models/Origin.php +++ b/app/Models/Origin.php @@ -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 { diff --git a/app/Models/Tagline.php b/app/Models/Tagline.php index 8688f0f..8dc1cf4 100644 --- a/app/Models/Tagline.php +++ b/app/Models/Tagline.php @@ -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 { diff --git a/app/Models/Tearline.php b/app/Models/Tearline.php index 30510f5..411e837 100644 --- a/app/Models/Tearline.php +++ b/app/Models/Tearline.php @@ -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 {