mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-11-09 14:51:35 +08:00
Resolve #437
This commit is contained in:
parent
9bb65609e2
commit
079f334bcc
4 changed files with 64 additions and 28 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { AbstractModel } from 'Knoin/AbstractModel';
|
import { AbstractModel } from 'Knoin/AbstractModel';
|
||||||
import { addObservablesTo } from 'External/ko';
|
import { addObservablesTo } from 'External/ko';
|
||||||
|
import Remote from 'Remote/User/Fetch';
|
||||||
|
|
||||||
export class AccountModel extends AbstractModel {
|
export class AccountModel extends AbstractModel {
|
||||||
/**
|
/**
|
||||||
|
|
@ -7,7 +8,7 @@ export class AccountModel extends AbstractModel {
|
||||||
* @param {boolean=} canBeDelete = true
|
* @param {boolean=} canBeDelete = true
|
||||||
* @param {number=} count = 0
|
* @param {number=} count = 0
|
||||||
*/
|
*/
|
||||||
constructor(email, name/*, count = 0*/, isAdditional = true) {
|
constructor(email, name, isAdditional = true) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
@ -16,17 +17,31 @@ export class AccountModel extends AbstractModel {
|
||||||
this.displayName = name ? name + ' <' + email + '>' : email;
|
this.displayName = name ? name + ' <' + email + '>' : email;
|
||||||
|
|
||||||
addObservablesTo(this, {
|
addObservablesTo(this, {
|
||||||
// count: count || 0,
|
unreadEmails: null,
|
||||||
askDelete: false,
|
askDelete: false,
|
||||||
isAdditional: isAdditional
|
isAdditional: isAdditional
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Load at random between 3 and 30 seconds
|
||||||
|
setTimeout(()=>this.fetchUnread(), (Math.ceil(Math.random() * 10)) * 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get INBOX unread messages
|
||||||
|
*/
|
||||||
|
fetchUnread() {
|
||||||
|
Remote.request('AccountUnread', (iError, oData) => {
|
||||||
|
iError || this.unreadEmails(oData?.Result?.unreadEmails || null);
|
||||||
|
}, {
|
||||||
|
email: this.email
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imports all mail to main account
|
* Imports all mail to main account
|
||||||
*//*
|
*//*
|
||||||
importAll(account) {
|
importAll(account) {
|
||||||
rl.app.Remote.streamPerLine(line => {
|
Remote.streamPerLine(line => {
|
||||||
try {
|
try {
|
||||||
line = JSON.parse(line);
|
line = JSON.parse(line);
|
||||||
console.dir(line);
|
console.dir(line);
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,25 @@
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.counter {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-menu a.account-item {
|
.dropdown-menu a.account-item {
|
||||||
padding-right: 5px;
|
padding-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span[data-unread]::after {
|
||||||
|
content: attr(data-unread);
|
||||||
|
background-color: var(--unread-count-bg-color, #999);
|
||||||
|
border-radius: 1em;
|
||||||
|
color: var(--unread-count-color, #fff);
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1.5em;
|
||||||
|
min-width: 1.7em;
|
||||||
|
padding: 1px 4px;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: 0 -1px 0 rgba(0,0,0,.25);
|
||||||
|
position: absolute;
|
||||||
|
right: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes equaliserBar {
|
@keyframes equaliserBar {
|
||||||
|
|
|
||||||
|
|
@ -110,37 +110,50 @@ trait Accounts
|
||||||
return $this->TrueResponse(__FUNCTION__);
|
return $this->TrueResponse(__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function loadAdditionalAccountImapClient(string $sEmail): \MailSo\Imap\ImapClient
|
||||||
* Imports all mail from AdditionalAccount into MainAccount
|
|
||||||
*/
|
|
||||||
public function DoAccountImport(): array
|
|
||||||
{
|
{
|
||||||
$sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($this->GetActionParam('email', '')), true);
|
$sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true);
|
||||||
if (!\strlen($sEmail)) {
|
if (!\strlen($sEmail)) {
|
||||||
throw new ClientException(Notifications::AccountDoesNotExist);
|
throw new ClientException(Notifications::AccountDoesNotExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oMainAccount = $this->getMainAccountFromToken();
|
$oMainAccount = $this->getMainAccountFromToken();
|
||||||
$oLogger = $this->Logger();
|
|
||||||
|
|
||||||
$aAccounts = $this->GetAccounts($oMainAccount);
|
$aAccounts = $this->GetAccounts($oMainAccount);
|
||||||
if (!isset($aAccounts[$sEmail])) {
|
if (!isset($aAccounts[$sEmail])) {
|
||||||
throw new ClientException(Notifications::AccountDoesNotExist);
|
throw new ClientException(Notifications::AccountDoesNotExist);
|
||||||
}
|
}
|
||||||
$oAccount = AdditionalAccount::NewInstanceFromTokenArray(
|
$oAccount = AdditionalAccount::NewInstanceFromTokenArray($this, $aAccounts[$sEmail]);
|
||||||
$this, $aAccounts[$sEmail]
|
|
||||||
);
|
|
||||||
if (!$oAccount) {
|
if (!$oAccount) {
|
||||||
throw new ClientException(Notifications::AccountDoesNotExist);
|
throw new ClientException(Notifications::AccountDoesNotExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oImapTarget = new \MailSo\Imap\ImapClient;
|
$oImapClient = new \MailSo\Imap\ImapClient;
|
||||||
$oImapTarget->SetLogger($oLogger);
|
$oImapClient->SetLogger($this->Logger());
|
||||||
$this->imapConnect($oMainAccount, false, $oImapTarget);
|
$this->imapConnect($oAccount, false, $oImapClient);
|
||||||
|
return $oImapClient;
|
||||||
|
}
|
||||||
|
|
||||||
$oImapSource = new \MailSo\Imap\ImapClient;
|
public function DoAccountUnread(): array
|
||||||
$oImapSource->SetLogger($oLogger);
|
{
|
||||||
$this->imapConnect($oAccount, false, $oImapSource);
|
$oImapClient = $this->loadAdditionalAccountImapClient($this->GetActionParam('email', ''));
|
||||||
|
$oInfo = $oImapClient->FolderStatus('INBOX');
|
||||||
|
return $this->DefaultResponse(__FUNCTION__, [
|
||||||
|
'unreadEmails' => \max(0, $oInfo->UNSEEN)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports all mail from AdditionalAccount into MainAccount
|
||||||
|
*/
|
||||||
|
public function DoAccountImport(): array
|
||||||
|
{
|
||||||
|
$sEmail = $this->GetActionParam('email', '');
|
||||||
|
$oImapSource = $this->loadAdditionalAccountImapClient($sEmail);
|
||||||
|
|
||||||
|
$oMainAccount = $this->getMainAccountFromToken();
|
||||||
|
$oImapTarget = new \MailSo\Imap\ImapClient;
|
||||||
|
$oImapTarget->SetLogger($this->Logger());
|
||||||
|
$this->imapConnect($oMainAccount, false, $oImapTarget);
|
||||||
|
|
||||||
$oSync = new \SnappyMail\Imap\Sync;
|
$oSync = new \SnappyMail\Imap\Sync;
|
||||||
$oSync->oImapSource = $oImapSource;
|
$oSync->oImapSource = $oImapSource;
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,8 @@
|
||||||
<!-- ko foreach: accounts -->
|
<!-- ko foreach: accounts -->
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a class="account-item" href="#" data-bind="click: $root.accountClick">
|
<a class="account-item" href="#" data-bind="click: $root.accountClick">
|
||||||
<!-- <b class="pull-right counter" data-bind="visible: count()">
|
|
||||||
<span data-bind="text: count, visible: 100 > count()"></span>
|
|
||||||
<span data-bind="visible: 99 < count()">99+</span>
|
|
||||||
</b>-->
|
|
||||||
<i class="fontastic" data-bind="text: $root.accountEmail() === email ? '✔' : '👤'"></i>
|
<i class="fontastic" data-bind="text: $root.accountEmail() === email ? '✔' : '👤'"></i>
|
||||||
<span class="email-title" data-bind="text: name || email, attr: {title: email}"></span>
|
<span class="email-title" data-bind="text: name || email, attr: {title: email, 'data-unread': unreadEmails}"></span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<!-- /ko -->
|
<!-- /ko -->
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue