diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index d195a98..f06de5d 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -673,7 +673,7 @@ class Message extends FTNBase * @return Echomail|Netmail * @throws InvalidPacketException */ - private function unpackMessage(string $message,Echomail|Netmail $o): Echomail|Netmail + public function unpackMessage(string $message,Echomail|Netmail $o): Echomail|Netmail { // Remove DOS \n\r $message = preg_replace("/\n\r/","\r",$message); @@ -796,6 +796,9 @@ class Message extends FTNBase $ptr_content_start = $ptr_end-$ptr_start; } + // Trim any right \r from the message + $o->msg = rtrim($o->msg,"\r"); + // Quick validation that we are done if ($ptr_content_start !== strlen($content)) throw new InvalidPacketException('There is more data in the message content?'); @@ -847,9 +850,6 @@ class Message extends FTNBase 'replyid' => 'sometimes|min:1', 'msg' => 'required|min:1', // @todo max message length? 'msg_crc' => 'required|size:32', - 'tagline' => 'sometimes|min:1|max:255', - 'tearline' => 'sometimes|min:1|max:255', - 'origin' => 'sometimes|min:1|max:255', 'local' => 'sometimes|boolean', 'fftn_id' => 'required|exists:App\Models\Address,id', 'tftn_id' => $this->isNetmail() ? 'required|exists:App\Models\Address,id' : 'prohibited', diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index c717043..5e35ac5 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -507,7 +507,7 @@ class SystemController extends Controller $no->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH); $no->cost = 0; - $no->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID); + $no->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID); $no->save(); Log::info(sprintf('%s:= Areafix to [%s], scheduling a poll',self::LOGKEY,$no->tftn->ftn)); diff --git a/app/Models/Echomail.php b/app/Models/Echomail.php index 3fe9b43..364bbec 100644 --- a/app/Models/Echomail.php +++ b/app/Models/Echomail.php @@ -46,6 +46,27 @@ final class Echomail extends Model implements Packet 'rogue_path' => CollectionOrNull::class, // @deprecated? ]; + public function __get($key) + { + switch ($key) { + case 'set_echoarea': + case 'set_fftn': + case 'set_path': + case 'set_pkt': + case 'set_recvtime': + case 'set_seenby': + case 'set_sender': + + case 'set_tagline': + case 'set_tearline': + case 'set_origin': + return $this->set->get($key); + + default: + return parent::__get($key); + } + } + public function __set($key,$value) { switch ($key) { @@ -71,7 +92,7 @@ final class Echomail extends Model implements Packet case 'set_pkt': case 'set_recvtime': case 'set_sender': - // @todo We'll normalise these values when saving the netmail + case 'set_tagline': case 'set_tearline': case 'set_origin': @@ -101,6 +122,26 @@ final class Echomail extends Model implements Packet static::creating(function($model) { 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_tearline')) + $model->tearline_id = Tearline::firstOrCreate(['value'=>$model->set_tearline])->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; + } + + // If we can rebuild the message content, then we can do away with msg_src + if (md5($model->rebuildMessage()) === $model->msg_crc) { + Log::debug(sprintf('%s:- Pruning message source, since we can rebuild the message [%s]',self::LOGKEY,$model->msgid)); + $model->msg_src = NULL; + } }); // @todo if the message is updated with new SEEN-BY's from another route, we'll delete the pending export for systems (if there is one) @@ -213,12 +254,6 @@ final class Echomail extends Model implements Packet return $this->belongsTo(Echoarea::class); } - public function fftn() - { - return $this->belongsTo(Address::class) - ->withTrashed(); - } - public function seenby() { return $this->belongsToMany(Address::class,'echomail_seenby') diff --git a/app/Models/Netmail.php b/app/Models/Netmail.php index 3cde67b..96f178b 100644 --- a/app/Models/Netmail.php +++ b/app/Models/Netmail.php @@ -45,6 +45,27 @@ final class Netmail extends Model implements Packet 'sent_at' => 'datetime:Y-m-d H:i:s', ]; + public function __get($key) + { + switch ($key) { + case 'set_fftn': + case 'set_tftn': + case 'set_path': + case 'set_pkt': + case 'set_recvtime': + case 'set_seenby': + case 'set_sender': + + case 'set_tagline': + case 'set_tearline': + case 'set_origin': + return $this->set->get($key); + + default: + return parent::__get($key); + } + } + public function __set($key,$value) { switch ($key) { @@ -67,7 +88,7 @@ final class Netmail extends Model implements Packet case 'set_pkt': case 'set_recvtime': case 'set_sender': - // @todo We'll normalise these values when saving the netmail + case 'set_tagline': case 'set_tearline': case 'set_origin': @@ -94,6 +115,26 @@ final class Netmail extends Model implements Packet static::creating(function($model) { 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_tearline')) + $model->tearline_id = Tearline::firstOrCreate(['value'=>$model->set_tearline])->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; + } + + // If we can rebuild the message content, then we can do away with msg_src + if (md5($model->rebuildMessage()) === $model->msg_crc) { + Log::debug(sprintf('%s:- Pruning message source, since we can rebuild the message [%s]',self::LOGKEY,$model->msgid)); + $model->msg_src = NULL; + } }); static::created(function($model) { @@ -160,27 +201,12 @@ final class Netmail extends Model implements Packet ]); } - // Save our origin, tearline & tagline - if ($model->set->has('set_tagline')) - $model->tagline = $model->set->get('set_tagline'); - if ($model->set->has('set_tearline')) - $model->tearline = $model->set->get('set_tearline'); - if ($model->set->has('set_origin')) - $model->origin = $model->set->get('set_origin'); - $model->save(); }); } /* RELATIONS */ - public function fftn() - { - return $this - ->belongsTo(Address::class) - ->withTrashed(); - } - public function path() { return $this->belongsToMany(Address::class,'netmail_path') diff --git a/app/Models/Origin.php b/app/Models/Origin.php new file mode 100644 index 0000000..017a270 --- /dev/null +++ b/app/Models/Origin.php @@ -0,0 +1,20 @@ +value,$o->point_id ? $o->ftn4d : $o->ftn3d); + } +} \ No newline at end of file diff --git a/app/Models/Tagline.php b/app/Models/Tagline.php new file mode 100644 index 0000000..8688f0f --- /dev/null +++ b/app/Models/Tagline.php @@ -0,0 +1,20 @@ +value); + } +} \ No newline at end of file diff --git a/app/Models/Tearline.php b/app/Models/Tearline.php new file mode 100644 index 0000000..30510f5 --- /dev/null +++ b/app/Models/Tearline.php @@ -0,0 +1,20 @@ +value); + } +} \ No newline at end of file diff --git a/app/Notifications/Echomails.php b/app/Notifications/Echomails.php index 6ee2788..ef88962 100644 --- a/app/Notifications/Echomails.php +++ b/app/Notifications/Echomails.php @@ -58,7 +58,7 @@ abstract class Echomails extends Notification //implements ShouldQueue $o->flags = (Message::FLAG_LOCAL); - $o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID); + $o->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID); return $o; } diff --git a/app/Notifications/Echomails/AbsentNodes.php b/app/Notifications/Echomails/AbsentNodes.php index ced3082..cbd92f8 100644 --- a/app/Notifications/Echomails/AbsentNodes.php +++ b/app/Notifications/Echomails/AbsentNodes.php @@ -48,7 +48,6 @@ class AbsentNodes extends Echomails $o->subject = 'Status changes for nodes'; $o->fftn_id = ($x=our_address($echoarea->domain)->last())->id; $o->kludges->put('CHRS:','CP437 2'); - $o->origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d); // Message $msg = new Page; @@ -95,7 +94,8 @@ class AbsentNodes extends Echomails $msg->addText("\rEmails and/or Netmails have been sent to these nodes. If you can help let them know that they have outstanding mail on the Hub, that would be helpful :)"); $o->msg = $msg->render(); - $o->tagline = 'When life gives you lemons, freeze them and throw them back.'; + $o->set_tagline = 'When life gives you lemons, freeze them and throw them back.'; + $o->set_origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d); $o->save(); diff --git a/app/Notifications/Echomails/Test.php b/app/Notifications/Echomails/Test.php index 6aee01d..e5d4cbe 100644 --- a/app/Notifications/Echomails/Test.php +++ b/app/Notifications/Echomails/Test.php @@ -50,7 +50,6 @@ class Test extends Echomails $o->replyid = $this->mo->msgid; $o->subject = 'Test Reply'; $o->kludges->put('CHRS:',$this->mo->kludges->get('chrs') ?: 'CP437 2'); - $o->origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d); // Message $msg = new Page; @@ -74,7 +73,8 @@ class Test extends Echomails $msg->addText($this->message_path($this->mo)); $o->msg = $msg->render(); - $o->tagline = 'I ate a clock yesterday, it was very time-consuming.'; + $o->set_tagline = 'I ate a clock yesterday, it was very time-consuming.'; + $o->set_origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d); $o->save(); diff --git a/app/Notifications/Netmails.php b/app/Notifications/Netmails.php index 1a5bc08..ad74eaa 100644 --- a/app/Notifications/Netmails.php +++ b/app/Notifications/Netmails.php @@ -64,7 +64,7 @@ abstract class Netmails extends Notification //implements ShouldQueue $o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE); $o->cost = 0; - $o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID); + $o->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID); return $o; } diff --git a/app/Notifications/Netmails/AddressLink.php b/app/Notifications/Netmails/AddressLink.php index c975fe0..9cc93cf 100644 --- a/app/Notifications/Netmails/AddressLink.php +++ b/app/Notifications/Netmails/AddressLink.php @@ -59,7 +59,7 @@ class AddressLink extends Netmails )); $o->msg = $msg->render(); - $o->tagline = 'Address Linking...'; + $o->set_tagline = 'Address Linking...'; $o->save(); diff --git a/app/Notifications/Netmails/Areafix.php b/app/Notifications/Netmails/Areafix.php index 1a86f38..7c98e63 100644 --- a/app/Notifications/Netmails/Areafix.php +++ b/app/Notifications/Netmails/Areafix.php @@ -55,7 +55,7 @@ class Areafix extends Netmails $msg->addText($this->message_path($this->mo)); $o->msg = $msg->render(); - $o->tagline = 'Why did the robot cross the road? The chicken programmed it.'; + $o->set_tagline = 'Why did the robot cross the road? The chicken programmed it.'; $o->save(); diff --git a/app/Notifications/Netmails/Areafix/NotConfiguredHere.php b/app/Notifications/Netmails/Areafix/NotConfiguredHere.php index b0cafba..9daeee8 100644 --- a/app/Notifications/Netmails/Areafix/NotConfiguredHere.php +++ b/app/Notifications/Netmails/Areafix/NotConfiguredHere.php @@ -55,7 +55,7 @@ class NotConfiguredHere extends Netmails $msg->addText($this->message_path($this->mo)); $o->msg = $msg->render(); - $o->tagline = 'Why did the robot cross the road? The chicken programmed it.'; + $o->set_tagline = 'Why did the robot cross the road? The chicken programmed it.'; $o->save(); diff --git a/app/Notifications/Netmails/EchoareaNoWrite.php b/app/Notifications/Netmails/EchoareaNoWrite.php index fc0a758..d599b09 100644 --- a/app/Notifications/Netmails/EchoareaNoWrite.php +++ b/app/Notifications/Netmails/EchoareaNoWrite.php @@ -63,7 +63,7 @@ class EchoareaNoWrite extends Netmails $msg->addText($this->message_path($this->mo)); $o->msg = $msg->render(); - $o->tagline = 'See something wrong? Do something right.'; + $o->set_tagline = 'See something wrong? Do something right.'; $o->save(); diff --git a/app/Notifications/Netmails/EchoareaNotExist.php b/app/Notifications/Netmails/EchoareaNotExist.php index 0565b11..30b7ffa 100644 --- a/app/Notifications/Netmails/EchoareaNotExist.php +++ b/app/Notifications/Netmails/EchoareaNotExist.php @@ -65,7 +65,7 @@ class EchoareaNotExist extends Netmails $msg->addText($this->message_path($this->mo)); $o->msg = $msg->render(); - $o->tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder often.'; + $o->set_tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder often.'; $o->save(); diff --git a/app/Notifications/Netmails/EchoareaNotSubscribed.php b/app/Notifications/Netmails/EchoareaNotSubscribed.php index 16cc738..3f0ac04 100644 --- a/app/Notifications/Netmails/EchoareaNotSubscribed.php +++ b/app/Notifications/Netmails/EchoareaNotSubscribed.php @@ -64,7 +64,7 @@ class EchoareaNotSubscribed extends Netmails $msg->addText($this->message_path($this->mo)); $o->msg = $msg->render(); - $o->tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder.'; + $o->set_tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder.'; $o->save(); diff --git a/app/Notifications/Netmails/EchomailBadAddress.php b/app/Notifications/Netmails/EchomailBadAddress.php index 80bb971..6b38d3d 100644 --- a/app/Notifications/Netmails/EchomailBadAddress.php +++ b/app/Notifications/Netmails/EchomailBadAddress.php @@ -64,7 +64,7 @@ class EchomailBadAddress extends Netmails $msg->addText($this->message_path($this->mo)); $o->msg = $msg->render(); - $o->tagline = 'I enjoyed reading your message, even though nobody else will get it :)'; + $o->set_tagline = 'I enjoyed reading your message, even though nobody else will get it :)'; $o->save(); diff --git a/app/Notifications/Netmails/NetmailForward.php b/app/Notifications/Netmails/NetmailForward.php index 3cb6103..5150a0a 100644 --- a/app/Notifications/Netmails/NetmailForward.php +++ b/app/Notifications/Netmails/NetmailForward.php @@ -61,7 +61,7 @@ class NetmailForward extends Netmails $msg->addText(sprintf("To avoid receiving this netmail, send messages to [%s] to [%s].\r\r",$this->mo->to,$this->ao->ftn3d)); $o->msg = $msg->render(); - $o->tagline = 'Thank you so much for your mail. I love it already.'; + $o->set_tagline = 'Thank you so much for your mail. I love it already.'; $o->save(); diff --git a/app/Notifications/Netmails/NetmailHubNoUser.php b/app/Notifications/Netmails/NetmailHubNoUser.php index 118f7d6..0fec377 100644 --- a/app/Notifications/Netmails/NetmailHubNoUser.php +++ b/app/Notifications/Netmails/NetmailHubNoUser.php @@ -64,7 +64,7 @@ class NetmailHubNoUser extends Netmails $msg->addText($this->message_path($this->mo)); $o->msg = $msg->render(); - $o->tagline = 'Do you think it was fate which brought us together? Nah, bad luck :('; + $o->set_tagline = 'Do you think it was fate which brought us together? Nah, bad luck :('; $o->save(); diff --git a/app/Notifications/Netmails/NodeDelisted.php b/app/Notifications/Netmails/NodeDelisted.php index 6590ca4..3cbdc92 100644 --- a/app/Notifications/Netmails/NodeDelisted.php +++ b/app/Notifications/Netmails/NodeDelisted.php @@ -50,7 +50,7 @@ class NodeDelisted extends Netmails //implements ShouldQueue ->addText(sprintf('If you think about returning to %s, then reach out and we can get you back online pretty quickly.',$x)); $o->msg = $msg->render(); - $o->tagline = 'You\'ve been DE-LISTED'; + $o->set_tagline = 'You\'ve been DE-LISTED'; $o->save(); diff --git a/app/Notifications/Netmails/NodeMarkedDown.php b/app/Notifications/Netmails/NodeMarkedDown.php index 58f5a04..3066bed 100644 --- a/app/Notifications/Netmails/NodeMarkedDown.php +++ b/app/Notifications/Netmails/NodeMarkedDown.php @@ -55,7 +55,7 @@ class NodeMarkedDown extends Netmails //implements ShouldQueue ->addText("If you think you've received this netmail by mistake or need help, please let me know.\r"); $o->msg = $msg->render(); - $o->tagline = 'Pending de-list'; + $o->set_tagline = 'Pending de-list'; $o->save(); diff --git a/app/Notifications/Netmails/NodeMarkedHold.php b/app/Notifications/Netmails/NodeMarkedHold.php index 565f2bc..d1816cf 100644 --- a/app/Notifications/Netmails/NodeMarkedHold.php +++ b/app/Notifications/Netmails/NodeMarkedHold.php @@ -55,7 +55,7 @@ class NodeMarkedHold extends Netmails //implements ShouldQueue ->addText("If you think you've received this netmail by mistake or need help, please let me know.\r"); $o->msg = $msg->render(); - $o->tagline = 'You\'ve been marked HOLD'; + $o->set_tagline = 'You\'ve been marked HOLD'; $o->save(); diff --git a/app/Notifications/Netmails/PacketPasswordInvalid.php b/app/Notifications/Netmails/PacketPasswordInvalid.php index 555d035..d8e79f3 100644 --- a/app/Notifications/Netmails/PacketPasswordInvalid.php +++ b/app/Notifications/Netmails/PacketPasswordInvalid.php @@ -62,7 +62,7 @@ class PacketPasswordInvalid extends Netmails $msg->addText("Head over to the website if you dont know what your packet password should be :)\r"); $o->msg = $msg->render(); - $o->tagline = 'Safety first, password second.'; + $o->set_tagline = 'Safety first, password second.'; $o->save(); diff --git a/app/Notifications/Netmails/Ping.php b/app/Notifications/Netmails/Ping.php index abc324c..38c327e 100644 --- a/app/Notifications/Netmails/Ping.php +++ b/app/Notifications/Netmails/Ping.php @@ -63,7 +63,7 @@ class Ping extends Netmails $msg->addText($this->message_path($this->mo)); $o->msg = $msg->render(); - $o->tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.'; + $o->set_tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.'; $o->save(); diff --git a/app/Notifications/Netmails/PollingFailed.php b/app/Notifications/Netmails/PollingFailed.php index 822ab3d..000f736 100644 --- a/app/Notifications/Netmails/PollingFailed.php +++ b/app/Notifications/Netmails/PollingFailed.php @@ -47,7 +47,7 @@ class PollingFailed extends Netmails $msg->addText("To fix this, update your details that I use in the web interface, or change your system to HOLD while you are there.\r\r"); $o->msg = $msg->render(); - $o->tagline = 'Painful? We can make that painless :)'; + $o->set_tagline = 'Painful? We can make that painless :)'; $o->save(); diff --git a/app/Notifications/Netmails/Test.php b/app/Notifications/Netmails/Test.php index 37b72f0..cc37e22 100644 --- a/app/Notifications/Netmails/Test.php +++ b/app/Notifications/Netmails/Test.php @@ -40,7 +40,7 @@ class Test extends Netmails ); $o->msg = $msg->render(); - $o->tagline = 'Testing, testing, 1 2 3.'; + $o->set_tagline = 'Testing, testing, 1 2 3.'; $o->save(); diff --git a/app/Traits/MessageAttributes.php b/app/Traits/MessageAttributes.php index 10db454..7d90971 100644 --- a/app/Traits/MessageAttributes.php +++ b/app/Traits/MessageAttributes.php @@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\MessageBag; use App\Classes\FTN\Message; -use App\Models\{Address,Echomail}; +use App\Models\{Address,Echomail,Origin,Tagline,Tearline}; trait MessageAttributes { @@ -28,26 +28,35 @@ trait MessageAttributes $this->set = collect(); } + /* RELATIONS */ + + public function fftn() + { + return $this + ->belongsTo(Address::class) + ->withTrashed(); + } + + public function origin() + { + return $this->belongsTo(Origin::class); + } + + public function tagline() + { + return $this->belongsTo(Tagline::class); + } + + public function tearline() + { + return $this->belongsTo(Tearline::class); + } + /* ATTRIBUTES */ public function getContentAttribute(): string { - if ($this->msg_src) - return $this->msg_src; - - // If we have a msg_src attribute, we'll use that - $result = $this->msg."\r\r"; - - if ($this->tagline) - $result .= sprintf("%s\r",$this->tagline); - - if ($this->tearline) - $result .= sprintf("%s\r",$this->tearline); - - if ($this->origin) - $result .= sprintf("%s",$this->origin); - - return rtrim($result,"\r"); + return ($this->msg_src) ? $this->msg_src : $this->rebuildMessage(); } public function getDateAttribute(): Carbon @@ -57,38 +66,35 @@ trait MessageAttributes public function getOriginAttribute(string $val=NULL): ?string { - if ($this->exists && (! $val)) - return $val; + if (($x=$this->getRelationValue('origin')) && $x->value) + return $x->complete($this->fftn); - // If $val is not set, then it may be an unsaved object - return sprintf(' * Origin: %s', - ((! $this->exists) && $this->set->has('set_origin')) - ? $this->set->get('set_origin') - : $val); + if (($this->set->has('set_origin')) || ($val)) + return sprintf(' * Origin: %s',$this->set->get('set_origin',$val)); + + return NULL; } public function getTaglineAttribute(string $val=NULL): ?string { - if ($this->exists && (! $val)) - return $val; + if (($x=$this->getRelationValue('tagline')) && $x->value) + return $x->complete(); - // If $val is not set, then it may be an unsaved object - return sprintf('... %s', - ((! $this->exists) && $this->set->has('set_tagline')) - ? $this->set->get('set_tagline') - : $val); + if (($this->set->has('set_tagline')) || ($val)) + return sprintf('... %s',$this->set->get('set_tagline',$val)); + + return NULL; } public function getTearlineAttribute(string $val=NULL): ?string { - if ($this->exists && (! $val)) - return $val; + if (($x=$this->getRelationValue('tearline')) && $x->value) + return $x->complete(); - // If $val is not set, then it may be an unsaved object - return sprintf('--- %s', - ((! $this->exists) && $this->set->has('set_tearline')) - ? $this->set->get('set_tearline') - : $val); + if (($this->set->has('set_tearline')) || ($val)) + return sprintf('--- %s',$this->set->get('set_tearline',$val)); + + return NULL; } /* METHODS */ @@ -164,6 +170,23 @@ trait MessageAttributes return Message::packMessage($this); } + public function rebuildMessage(): string + { + // If we have a msg_src attribute, we'll use that + $result = $this->msg."\r"; + + if ($x=$this->tagline) + $result .= sprintf("%s\r",$x); + + if ($x=$this->tearline) + $result .= sprintf("%s\r",$x); + + if ($x=$this->origin) + $result .= sprintf("%s",$x); + + return rtrim($result,"\r"); + } + /** * Return our path in order * diff --git a/database/migrations/2024_06_03_072631_msg_attributes.php b/database/migrations/2024_06_03_072631_msg_attributes.php new file mode 100644 index 0000000..7284d86 --- /dev/null +++ b/database/migrations/2024_06_03_072631_msg_attributes.php @@ -0,0 +1,81 @@ +id(); + $table->timestamp('created_at'); + $table->softDeletes(); + $table->string('value')->unique(); + }); + + Schema::create('tearlines', function (Blueprint $table) { + $table->id(); + $table->timestamp('created_at'); + $table->softDeletes(); + $table->string('value')->unique(); + }); + + Schema::create('origins', function (Blueprint $table) { + $table->id(); + $table->timestamp('created_at'); + $table->softDeletes(); + $table->string('value')->unique(); + }); + + Schema::table('echomails', function (Blueprint $table) { + $table->bigInteger('tagline_id')->nullable(); + $table->foreign('tagline_id')->references('id')->on('taglines'); + + $table->bigInteger('tearline_id')->nullable(); + $table->foreign('tearline_id')->references('id')->on('tearlines'); + + $table->bigInteger('origin_id')->nullable(); + $table->foreign('origin_id')->references('id')->on('origins'); + }); + + Schema::table('netmails', function (Blueprint $table) { + $table->bigInteger('tagline_id')->nullable(); + $table->foreign('tagline_id')->references('id')->on('taglines'); + + $table->bigInteger('tearline_id')->nullable(); + $table->foreign('tearline_id')->references('id')->on('tearlines'); + + $table->bigInteger('origin_id')->nullable(); + $table->foreign('origin_id')->references('id')->on('origins'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('netmails', function (Blueprint $table) { + $table->dropForeign(['tagline_id']); + $table->dropForeign(['tearline_id']); + $table->dropForeign(['origin_id']); + $table->dropColumn(['tagline_id','tearline_id','origin_id']); + }); + + Schema::table('echomails', function (Blueprint $table) { + $table->dropForeign(['tagline_id']); + $table->dropForeign(['tearline_id']); + $table->dropForeign(['origin_id']); + $table->dropColumn(['tagline_id','tearline_id','origin_id']); + }); + + Schema::dropIfExists('origins'); + Schema::dropIfExists('tearlines'); + Schema::dropIfExists('taglines'); + } +};