mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 00:17:03 +03:00
Cleanup message attachments collections
This commit is contained in:
parent
eb669715ca
commit
94bfe09f63
6 changed files with 28 additions and 34 deletions
|
|
@ -249,10 +249,10 @@ export const FileInfo = {
|
||||||
* @param {string} sFileType
|
* @param {string} sFileType
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
getCombinedIconClass: data => {
|
getAttachmentsIconClass: data => {
|
||||||
if (arrayLength(data)) {
|
if (arrayLength(data)) {
|
||||||
let icons = data
|
let icons = data
|
||||||
.map(item => item ? FileInfo.getIconClass(FileInfo.getExtension(item[0]), item[1]) : '')
|
.map(item => item ? FileInfo.getIconClass(FileInfo.getExtension(item.fileName), item.mimeType) : '')
|
||||||
.validUnique();
|
.validUnique();
|
||||||
|
|
||||||
return (icons && 1 === icons.length && 'icon-file' !== icons[0])
|
return (icons && 1 === icons.length && 'icon-file' !== icons[0])
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,13 @@ export class AttachmentCollectionModel extends AbstractCollectionModel
|
||||||
*/
|
*/
|
||||||
static reviveFromJson(items) {
|
static reviveFromJson(items) {
|
||||||
return super.reviveFromJson(items, attachment => AttachmentModel.reviveFromJson(attachment));
|
return super.reviveFromJson(items, attachment => AttachmentModel.reviveFromJson(attachment));
|
||||||
|
/*
|
||||||
|
const attachments = super.reviveFromJson(items, attachment => AttachmentModel.reviveFromJson(attachment));
|
||||||
|
if (attachments) {
|
||||||
|
attachments.InlineCount = attachments.reduce((accumulator, a) => accumulator + (a.isInline ? 1 : 0), 0);
|
||||||
|
}
|
||||||
|
return attachments;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -77,13 +77,12 @@ export class MessageModel extends AbstractModel {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.attachments = ko.observableArray(new AttachmentCollectionModel);
|
this.attachments = ko.observableArray(new AttachmentCollectionModel);
|
||||||
this.attachmentsSpecData = ko.observableArray();
|
|
||||||
this.threads = ko.observableArray();
|
this.threads = ko.observableArray();
|
||||||
this.unsubsribeLinks = ko.observableArray();
|
this.unsubsribeLinks = ko.observableArray();
|
||||||
this.flags = ko.observableArray();
|
this.flags = ko.observableArray();
|
||||||
|
|
||||||
this.addComputables({
|
this.addComputables({
|
||||||
attachmentIconClass: () => FileInfo.getCombinedIconClass(this.hasAttachments() ? this.attachmentsSpecData() : []),
|
attachmentIconClass: () => FileInfo.getAttachmentsIconClass(this.attachments()),
|
||||||
threadsLen: () => this.threads().length,
|
threadsLen: () => this.threads().length,
|
||||||
isImportant: () => MessagePriority.High === this.priority(),
|
isImportant: () => MessagePriority.High === this.priority(),
|
||||||
|
|
||||||
|
|
@ -137,7 +136,6 @@ export class MessageModel extends AbstractModel {
|
||||||
this.selected(false);
|
this.selected(false);
|
||||||
this.checked(false);
|
this.checked(false);
|
||||||
this.hasAttachments(false);
|
this.hasAttachments(false);
|
||||||
this.attachmentsSpecData([]);
|
|
||||||
|
|
||||||
this.isHtml(false);
|
this.isHtml(false);
|
||||||
this.hasImages(false);
|
this.hasImages(false);
|
||||||
|
|
@ -190,6 +188,7 @@ export class MessageModel extends AbstractModel {
|
||||||
json.Priority = MessagePriority.Normal;
|
json.Priority = MessagePriority.Normal;
|
||||||
}
|
}
|
||||||
if (super.revivePropertiesFromJson(json)) {
|
if (super.revivePropertiesFromJson(json)) {
|
||||||
|
this.hasAttachments(!!this.attachments.length);
|
||||||
// this.foundCIDs = isArray(json.FoundCIDs) ? json.FoundCIDs : [];
|
// this.foundCIDs = isArray(json.FoundCIDs) ? json.FoundCIDs : [];
|
||||||
// this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundCIDs));
|
// this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundCIDs));
|
||||||
|
|
||||||
|
|
@ -441,7 +440,7 @@ export class MessageModel extends AbstractModel {
|
||||||
this.selected(message.selected());
|
this.selected(message.selected());
|
||||||
this.checked(message.checked());
|
this.checked(message.checked());
|
||||||
this.hasAttachments(message.hasAttachments());
|
this.hasAttachments(message.hasAttachments());
|
||||||
this.attachmentsSpecData(message.attachmentsSpecData());
|
this.attachments(message.attachments());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.body = null;
|
this.body = null;
|
||||||
|
|
|
||||||
|
|
@ -23,32 +23,20 @@ class AttachmentCollection extends \MailSo\Base\Collection
|
||||||
parent::append($oAttachment, $bToTop);
|
parent::append($oAttachment, $bToTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function InlineCount() : int
|
|
||||||
{
|
|
||||||
$iCount = 0;
|
|
||||||
foreach ($this as $oAttachment) {
|
|
||||||
if ($oAttachment && $oAttachment->IsInline()) {
|
|
||||||
++$iCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $iCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function SpecData() : array
|
public function SpecData() : array
|
||||||
{
|
{
|
||||||
$aResult = array();
|
$aResult = array();
|
||||||
foreach ($this as $oAttachment) {
|
foreach ($this as $oAttachment) {
|
||||||
$aResult[] = $oAttachment
|
$aResult[] = array(
|
||||||
? array($oAttachment->FileName(true), $oAttachment->MimeType())
|
'@Object' => 'Object/Attachment',
|
||||||
: null;
|
'FileName' => $oAttachment->FileName(true),
|
||||||
|
'MimeType' => $oAttachment->MimeType(),
|
||||||
|
'IsInline' => $oAttachment->IsInline()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return $aResult;
|
return array(
|
||||||
}
|
'@Object' => 'Collection/AttachmentCollection',
|
||||||
|
'@Collection' => $aResult
|
||||||
public function jsonSerialize()
|
);
|
||||||
{
|
|
||||||
return array_merge(parent::jsonSerialize(), array(
|
|
||||||
'InlineCount' => $this->InlineCount()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -654,8 +654,7 @@ class Message implements \JsonSerializable
|
||||||
'UnsubsribeLinks' => $this->aUnsubsribeLinks,
|
'UnsubsribeLinks' => $this->aUnsubsribeLinks,
|
||||||
'ReadReceipt' => '',
|
'ReadReceipt' => '',
|
||||||
|
|
||||||
'HasAttachments' => $this->oAttachments && 0 < $this->oAttachments->count(),
|
'Attachments' => $this->oAttachments ? $this->oAttachments->SpecData() : null,
|
||||||
'AttachmentsSpecData' => $this->oAttachments ? $this->oAttachments->SpecData() : array(),
|
|
||||||
|
|
||||||
'Flags' => $this->aFlagsLowerCase
|
'Flags' => $this->aFlagsLowerCase
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -202,13 +202,12 @@ trait Response
|
||||||
|
|
||||||
if ('Message' === $sParent)
|
if ('Message' === $sParent)
|
||||||
{
|
{
|
||||||
$oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments();
|
|
||||||
|
|
||||||
$bHasExternals = false;
|
$bHasExternals = false;
|
||||||
$mFoundCIDs = array();
|
$mFoundCIDs = array();
|
||||||
$aContentLocationUrls = array();
|
$aContentLocationUrls = array();
|
||||||
$mFoundContentLocationUrls = array();
|
$mFoundContentLocationUrls = array();
|
||||||
|
|
||||||
|
$oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments();
|
||||||
if ($oAttachments && 0 < $oAttachments->count())
|
if ($oAttachments && 0 < $oAttachments->count())
|
||||||
{
|
{
|
||||||
foreach ($oAttachments as /* @var \MailSo\Mail\Attachment */ $oAttachment)
|
foreach ($oAttachments as /* @var \MailSo\Mail\Attachment */ $oAttachment)
|
||||||
|
|
@ -218,7 +217,7 @@ trait Response
|
||||||
$sContentLocation = $oAttachment->ContentLocation();
|
$sContentLocation = $oAttachment->ContentLocation();
|
||||||
if ($sContentLocation && \strlen($sContentLocation))
|
if ($sContentLocation && \strlen($sContentLocation))
|
||||||
{
|
{
|
||||||
$aContentLocationUrls[] = $oAttachment->ContentLocation();
|
$aContentLocationUrls[] = $sContentLocation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -273,12 +272,14 @@ trait Response
|
||||||
$mResult['HasExternals'] = $bHasExternals;
|
$mResult['HasExternals'] = $bHasExternals;
|
||||||
$mResult['HasInternals'] = (\is_array($mFoundCIDs) && \count($mFoundCIDs)) ||
|
$mResult['HasInternals'] = (\is_array($mFoundCIDs) && \count($mFoundCIDs)) ||
|
||||||
(\is_array($mFoundContentLocationUrls) && \count($mFoundContentLocationUrls));
|
(\is_array($mFoundContentLocationUrls) && \count($mFoundContentLocationUrls));
|
||||||
|
$mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, $aParameters);
|
||||||
|
/*
|
||||||
// $mResult['FoundCIDs'] = $mFoundCIDs;
|
// $mResult['FoundCIDs'] = $mFoundCIDs;
|
||||||
$mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, \array_merge($aParameters, array(
|
$mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, \array_merge($aParameters, array(
|
||||||
'FoundCIDs' => $mFoundCIDs,
|
'FoundCIDs' => $mFoundCIDs,
|
||||||
'FoundContentLocationUrls' => $mFoundContentLocationUrls
|
'FoundContentLocationUrls' => $mFoundContentLocationUrls
|
||||||
)));
|
)));
|
||||||
|
*/
|
||||||
$mResult['ReadReceipt'] = $mResponse->ReadReceipt();
|
$mResult['ReadReceipt'] = $mResponse->ReadReceipt();
|
||||||
|
|
||||||
if (\strlen($mResult['ReadReceipt']) && !\in_array('$forwarded', $mResult['Flags']))
|
if (\strlen($mResult['ReadReceipt']) && !\in_array('$forwarded', $mResult['Flags']))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue