mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-11-08 06:11:37 +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 { addObservablesTo } from 'External/ko';
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
export class AccountModel extends AbstractModel {
|
||||
/**
|
||||
|
|
@ -7,7 +8,7 @@ export class AccountModel extends AbstractModel {
|
|||
* @param {boolean=} canBeDelete = true
|
||||
* @param {number=} count = 0
|
||||
*/
|
||||
constructor(email, name/*, count = 0*/, isAdditional = true) {
|
||||
constructor(email, name, isAdditional = true) {
|
||||
super();
|
||||
|
||||
this.name = name;
|
||||
|
|
@ -16,17 +17,31 @@ export class AccountModel extends AbstractModel {
|
|||
this.displayName = name ? name + ' <' + email + '>' : email;
|
||||
|
||||
addObservablesTo(this, {
|
||||
// count: count || 0,
|
||||
unreadEmails: null,
|
||||
askDelete: false,
|
||||
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
|
||||
*//*
|
||||
importAll(account) {
|
||||
rl.app.Remote.streamPerLine(line => {
|
||||
Remote.streamPerLine(line => {
|
||||
try {
|
||||
line = JSON.parse(line);
|
||||
console.dir(line);
|
||||
|
|
|
|||
|
|
@ -69,13 +69,25 @@
|
|||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.counter {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.dropdown-menu a.account-item {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -110,37 +110,50 @@ trait Accounts
|
|||
return $this->TrueResponse(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports all mail from AdditionalAccount into MainAccount
|
||||
*/
|
||||
public function DoAccountImport(): array
|
||||
protected function loadAdditionalAccountImapClient(string $sEmail): \MailSo\Imap\ImapClient
|
||||
{
|
||||
$sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($this->GetActionParam('email', '')), true);
|
||||
$sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true);
|
||||
if (!\strlen($sEmail)) {
|
||||
throw new ClientException(Notifications::AccountDoesNotExist);
|
||||
}
|
||||
|
||||
$oMainAccount = $this->getMainAccountFromToken();
|
||||
$oLogger = $this->Logger();
|
||||
|
||||
$aAccounts = $this->GetAccounts($oMainAccount);
|
||||
if (!isset($aAccounts[$sEmail])) {
|
||||
throw new ClientException(Notifications::AccountDoesNotExist);
|
||||
}
|
||||
$oAccount = AdditionalAccount::NewInstanceFromTokenArray(
|
||||
$this, $aAccounts[$sEmail]
|
||||
);
|
||||
$oAccount = AdditionalAccount::NewInstanceFromTokenArray($this, $aAccounts[$sEmail]);
|
||||
if (!$oAccount) {
|
||||
throw new ClientException(Notifications::AccountDoesNotExist);
|
||||
}
|
||||
|
||||
$oImapTarget = new \MailSo\Imap\ImapClient;
|
||||
$oImapTarget->SetLogger($oLogger);
|
||||
$this->imapConnect($oMainAccount, false, $oImapTarget);
|
||||
$oImapClient = new \MailSo\Imap\ImapClient;
|
||||
$oImapClient->SetLogger($this->Logger());
|
||||
$this->imapConnect($oAccount, false, $oImapClient);
|
||||
return $oImapClient;
|
||||
}
|
||||
|
||||
$oImapSource = new \MailSo\Imap\ImapClient;
|
||||
$oImapSource->SetLogger($oLogger);
|
||||
$this->imapConnect($oAccount, false, $oImapSource);
|
||||
public function DoAccountUnread(): array
|
||||
{
|
||||
$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->oImapSource = $oImapSource;
|
||||
|
|
|
|||
|
|
@ -19,12 +19,8 @@
|
|||
<!-- ko foreach: accounts -->
|
||||
<li role="presentation">
|
||||
<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>
|
||||
<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>
|
||||
</li>
|
||||
<!-- /ko -->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue