cleanup some json code

This commit is contained in:
the-djmaze 2023-01-25 09:41:15 +01:00
parent f23b7205c6
commit 528b6cd096
5 changed files with 19 additions and 12 deletions

View file

@ -80,11 +80,9 @@ export class AbstractModel {
} }
revivePropertiesFromJson(json) { revivePropertiesFromJson(json) {
let model = this.constructor; const model = this.constructor,
if (!model.validJson(json)) { valid = model.validJson(json);
return false; valid && forEachObjectEntry(json, (key, value) => {
}
forEachObjectEntry(json, (key, value) => {
if ('@' !== key[0]) try { if ('@' !== key[0]) try {
// key = key[0].toLowerCase() + key.slice(1); // key = key[0].toLowerCase() + key.slice(1);
switch (typeof this[key]) switch (typeof this[key])
@ -103,9 +101,11 @@ export class AbstractModel {
this[key] = typeCast(this[key], value); this[key] = typeCast(this[key], value);
break; break;
case 'undefined': case 'undefined':
console.log(`Undefined ${model.name}.${key} set`);
this[key] = value; this[key] = value;
// fall through break;
default: // default:
// console.log((typeof this[key])+` ${model.name}.${key} not revived`);
// console.log((typeof this[key])+' '+(model.name)+'.'+key+' not revived'); // console.log((typeof this[key])+' '+(model.name)+'.'+key+' not revived');
} }
} catch (e) { } catch (e) {
@ -113,7 +113,7 @@ export class AbstractModel {
console.error(e); console.error(e);
} }
}); });
return true; return valid;
} }
} }

View file

@ -18,6 +18,7 @@ export class AttachmentModel extends AbstractModel {
this.checked = ko.observable(true); this.checked = ko.observable(true);
this.mimeType = ''; this.mimeType = '';
// this.mimeTypeParams = '';
this.fileName = ''; this.fileName = '';
this.fileNameExt = ''; this.fileNameExt = '';
this.fileType = FileType.Unknown; this.fileType = FileType.Unknown;

View file

@ -74,6 +74,7 @@ export class MessageModel extends AbstractModel {
this.to = new EmailCollectionModel; this.to = new EmailCollectionModel;
this.cc = new EmailCollectionModel; this.cc = new EmailCollectionModel;
this.bcc = new EmailCollectionModel; this.bcc = new EmailCollectionModel;
this.sender = new EmailCollectionModel;
this.replyTo = new EmailCollectionModel; this.replyTo = new EmailCollectionModel;
this.deliveredTo = new EmailCollectionModel; this.deliveredTo = new EmailCollectionModel;
this.body = null; this.body = null;
@ -120,6 +121,11 @@ export class MessageModel extends AbstractModel {
readReceipt: '', readReceipt: '',
autocrypt: '',
// rfc8621
id: '',
// threadId: '',
hasUnseenSubMessage: false, hasUnseenSubMessage: false,
hasFlaggedSubMessage: false hasFlaggedSubMessage: false
}); });

View file

@ -528,7 +528,7 @@ class BodyStructure implements \JsonSerializable
return array( return array(
'mimeIndex' => $this->sPartID, 'mimeIndex' => $this->sPartID,
'mimeType' => $this->sContentType, 'mimeType' => $this->sContentType,
'mimeTypeParams' => $this->aContentTypeParams, // 'mimeTypeParams' => $this->aContentTypeParams,
'fileName' => \MailSo\Base\Utils::SecureFileName($this->FileName(true)), 'fileName' => \MailSo\Base\Utils::SecureFileName($this->FileName(true)),
'estimatedSize' => $this->EstimatedSize(), 'estimatedSize' => $this->EstimatedSize(),
'cId' => $this->sContentID, 'cId' => $this->sContentID,

View file

@ -380,11 +380,11 @@ class Message implements \JsonSerializable
. \trim($oFetchResponse->GetFetchValue(FetchType::BODY.'['.$oMessage->pgpSigned['bodyPartId'].']')) . \trim($oFetchResponse->GetFetchValue(FetchType::BODY.'['.$oMessage->pgpSigned['bodyPartId'].']'))
); );
if ($sPgpText) { if ($sPgpText) {
$oMessage->pgpSigned['Body'] = $sPgpText; $oMessage->pgpSigned['body'] = $sPgpText;
} }
$sPgpSignatureText = $oFetchResponse->GetFetchValue(FetchType::BODY.'['.$oMessage->pgpSigned['sigPartId'].']'); $sPgpSignatureText = $oFetchResponse->GetFetchValue(FetchType::BODY.'['.$oMessage->pgpSigned['sigPartId'].']');
if ($sPgpSignatureText && 0 < \strpos($sPgpSignatureText, 'BEGIN PGP SIGNATURE')) { if ($sPgpSignatureText && 0 < \strpos($sPgpSignatureText, 'BEGIN PGP SIGNATURE')) {
$oMessage->pgpSigned['Signature'] = $oPart->SubParts()[0]->PartID(); $oMessage->pgpSigned['signature'] = $oPart->SubParts()[0]->PartID();
} }
*/ */
break; break;
@ -527,7 +527,7 @@ class Message implements \JsonSerializable
// https://datatracker.ietf.org/doc/html/rfc8621#section-4.1.1 // https://datatracker.ietf.org/doc/html/rfc8621#section-4.1.1
'id' => $this->sEmailId, 'id' => $this->sEmailId,
// 'blobId' => $this->sEmailIdBlob, // 'blobId' => $this->sEmailIdBlob,
'threadId' => $this->sThreadId, // 'threadId' => $this->sThreadId,
// 'mailboxIds' => ['mailboxid'=>true], // 'mailboxIds' => ['mailboxid'=>true],
// 'keywords' => $keywords, // 'keywords' => $keywords,
'size' => $this->iSize 'size' => $this->iSize