Enable UTF8 encoding to/from as well in messages
This commit is contained in:
parent
f1780e61ea
commit
3a1c6d55c6
@ -27,6 +27,8 @@ class Message extends FTNBase
|
|||||||
private const LOGKEY = 'FM-';
|
private const LOGKEY = 'FM-';
|
||||||
|
|
||||||
private const cast_utf8 = [
|
private const cast_utf8 = [
|
||||||
|
'user_to',
|
||||||
|
'user_from',
|
||||||
'subject',
|
'subject',
|
||||||
'message',
|
'message',
|
||||||
'message_src',
|
'message_src',
|
||||||
@ -697,6 +699,7 @@ class Message extends FTNBase
|
|||||||
// If there was no return, its part of the message.
|
// If there was no return, its part of the message.
|
||||||
if ($retpos === FALSE) {
|
if ($retpos === FALSE) {
|
||||||
$this->message .= "\x01".$kl;
|
$this->message .= "\x01".$kl;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -704,20 +707,17 @@ class Message extends FTNBase
|
|||||||
if ($originpos = strrpos($kl,"\r * Origin: ")) {
|
if ($originpos = strrpos($kl,"\r * Origin: ")) {
|
||||||
if (! $this->message) {
|
if (! $this->message) {
|
||||||
$this->message .= substr($kl,$retpos+1,$originpos-$retpos-1);
|
$this->message .= substr($kl,$retpos+1,$originpos-$retpos-1);
|
||||||
$this->parseOrigin(substr($kl,$originpos+1));
|
|
||||||
$kl = substr($kl,0,$retpos);
|
|
||||||
|
|
||||||
$this->message_src = substr($message, 0, $msgpos - strlen($kl) + 9);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->message .= "\x01".substr($kl,0,$originpos);
|
$this->message .= "\x01".substr($kl,0,$originpos);
|
||||||
$this->parseOrigin(substr($kl,$originpos+1));
|
|
||||||
|
|
||||||
// Capture the raw message, in case we send it on
|
$retpos = 0;
|
||||||
$this->message_src = substr($message, 0, $msgpos - strlen($kl) - 1 + $originpos + 12 + strlen($this->origin) + 1);
|
|
||||||
$kl = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->parseOrigin(substr($kl,$originpos+1));
|
||||||
|
$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
|
// If this is netmail, the FQFA will have been set by the INTL line, we can skip the rest of this
|
||||||
$matches = [];
|
$matches = [];
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ final class Echomail extends Model implements Packet
|
|||||||
protected $casts = [ 'kludges' => 'json' ];
|
protected $casts = [ 'kludges' => 'json' ];
|
||||||
|
|
||||||
private const cast_utf8 = [
|
private const cast_utf8 = [
|
||||||
|
'to',
|
||||||
|
'from',
|
||||||
'subject',
|
'subject',
|
||||||
'msg',
|
'msg',
|
||||||
'origin',
|
'origin',
|
||||||
|
@ -18,6 +18,8 @@ final class Netmail extends Model implements Packet
|
|||||||
use SoftDeletes,UseMongo,EncodeUTF8;
|
use SoftDeletes,UseMongo,EncodeUTF8;
|
||||||
|
|
||||||
private const cast_utf8 = [
|
private const cast_utf8 = [
|
||||||
|
'to',
|
||||||
|
'from',
|
||||||
'subject',
|
'subject',
|
||||||
'msg',
|
'msg',
|
||||||
'origin',
|
'origin',
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
trait EncodeUTF8
|
trait EncodeUTF8
|
||||||
{
|
{
|
||||||
private function decode(array $values): void
|
private function decode(array $values): void
|
||||||
@ -14,28 +16,30 @@ trait EncodeUTF8
|
|||||||
$class = get_class($this);
|
$class = get_class($this);
|
||||||
|
|
||||||
foreach ($properties as $property) {
|
foreach ($properties as $property) {
|
||||||
if ($property->isStatic()) {
|
if ($property->isStatic())
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
$name = $property->getName();
|
$name = $property->getName();
|
||||||
$decode = in_array($name,self::cast_utf8);
|
$decode = in_array($name,self::cast_utf8);
|
||||||
|
|
||||||
if ($property->isPrivate()) {
|
if ($property->isPrivate())
|
||||||
$name = "\0{$class}\0{$name}";
|
$name = "\0{$class}\0{$name}";
|
||||||
} elseif ($property->isProtected()) {
|
elseif ($property->isProtected())
|
||||||
$name = "\0*\0{$name}";
|
$name = "\0*\0{$name}";
|
||||||
}
|
|
||||||
|
|
||||||
if (! array_key_exists($name,$values)) {
|
if (! array_key_exists($name,$values))
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
|
||||||
|
try {
|
||||||
$property->setValue(
|
$property->setValue(
|
||||||
$this,$decode ? utf8_decode($values[$name]) : $values[$name]
|
$this,$decode ? utf8_decode($values[$name]) : $values[$name]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
dd(['e'=>$e->getMessage(),'name'=>$name,'values'=>$values[$name],'decode'=>$decode]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,34 +53,44 @@ trait EncodeUTF8
|
|||||||
|
|
||||||
foreach ($properties as $property) {
|
foreach ($properties as $property) {
|
||||||
// Dont serialize the validation error
|
// Dont serialize the validation error
|
||||||
if ($property->name == 'errors')
|
if (($property->name == 'errors') || $property->isStatic())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ($property->isStatic()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
|
||||||
if (! $property->isInitialized($this)) {
|
if (! $property->isInitialized($this))
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
$name = $property->getName();
|
$name = $property->getName();
|
||||||
$encode = in_array($name,self::cast_utf8);
|
$encode = in_array($name,self::cast_utf8);
|
||||||
|
|
||||||
if ($property->isPrivate()) {
|
if ($property->isPrivate())
|
||||||
$name = "\0{$class}\0{$name}";
|
$name = "\0{$class}\0{$name}";
|
||||||
} elseif ($property->isProtected()) {
|
elseif ($property->isProtected())
|
||||||
$name = "\0*\0{$name}";
|
$name = "\0*\0{$name}";
|
||||||
}
|
|
||||||
|
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$value = $property->getValue($this);
|
$value = $property->getValue($this);
|
||||||
|
|
||||||
$values[$name] = $encode ? utf8_encode($value) : $value;
|
$values[$name] = $encode ? utf8_encode($value) : $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAttribute($key)
|
||||||
|
{
|
||||||
|
static $encoded = [];
|
||||||
|
|
||||||
|
if (in_array($key,self::cast_utf8) && Arr::get($this->attributes,$key) && (! Arr::get($encoded,$key))) {
|
||||||
|
$this->attributes[$key] = utf8_decode($this->attributes[$key]);
|
||||||
|
$encoded[$key] = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getAttribute($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAttribute($key,$value)
|
||||||
|
{
|
||||||
|
return parent::setAttribute($key,in_array($key,self::cast_utf8) ? utf8_encode($value) : $value);
|
||||||
|
}
|
||||||
}
|
}
|
@ -91,10 +91,10 @@
|
|||||||
|
|
||||||
<div class="row pb-2">
|
<div class="row pb-2">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
FROM: <strong class="highlight">{{ $msg->user_from }}</strong> (<strong class="highlight">{{ $msg->fftn }}</strong>)
|
FROM: <strong class="highlight">{!! \App\Classes\FTN\Message::tr($msg->user_from) !!}</strong> (<strong class="highlight">{{ $msg->fftn }}</strong>)
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
TO: <strong class="highlight">{{ $msg->user_to }}</strong> (<strong class="highlight">{{ $msg->tftn }}</strong>)
|
TO: <strong class="highlight">{!! \App\Classes\FTN\Message::tr($msg->user_to) !!}</strong> XX(<strong class="highlight">{{ $msg->tftn }}</strong>)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
<div class="row pb-2">
|
<div class="row pb-2">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
FROM: <strong class="highlight">{{ $msg->from }}</strong> (<strong class="highlight">{{ $msg->fftn->ftn }}</strong>)
|
FROM: <strong class="highlight">{!! \App\Classes\FTN\Message::tr($msg->from) !!}</strong> (<strong class="highlight">{{ $msg->fftn->ftn }}</strong>)
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
TO: <strong class="highlight">{{ $msg->to }}</strong>
|
TO: <strong class="highlight">{!! \App\Classes\FTN\Message::tr($msg->to) !!}</strong>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user