EvanMailboxService

Source mailbox

Blockchain core description class wrapper.

  • mails - object[]: all mail cache;
  • newMailCount - number (default = 0): newly received mail count;
  • readMails - Array<string>: all mails that were already viewed (cached into local storage);
  • receivedMails - object[]: received mail cache;
  • sendMailQueueId - qr-code-scanner module: queue id to handle mail sending;
  • sentMails - object[]: send mail cache;
  • totalReceivedMailCount - number: total received mail count;
  • totalSentMailCount - number: total sent mail count;

checkNewMails

mailboxService.checkNewMails();

Check for new mails and set the newMails property to false / true when new mails incoming

Returns

Promise returns void: resolved when done

Example

setInterval(() => this.mailboxService.checkNewMails());

getReadMails

mailboxService.getReadMails();

Check read mails within localStorage cache and return them.

Returns

Array<string>: readed mails from localStorage

Example

this.mailboxService.getReadMails() // [ '0x00...', '0x100...' ]

getReadMailsCount

mailboxService.getReadMailsCount();

Get read mail count

Returns

number: count of read mails

Example

this.mailboxService.getReadMailsCount()

addReadMails

mailboxService.addReadMails(mailId);

Add a mail id to the mail read array within the localStorage

Parameters

  1. mailId - string: mail id

Example

this.mailboxService.addReadMails(mail.address || '0x00');

syncLastReadCount

mailboxService.syncLastReadCount();

Check for new mails and update the last read mail count

Example

this.mailboxService.syncLastReadCount();

showMailModal

mailboxService.showMailModal(modalService, alertTitle, alertText, title, body);

Show a mail modal, to provide the user the possility to change the email text before sending.

Have a look at MailDialogComponent

Parameters

  1. modalService - string: modal service (must to be inclued, to prevent recursive services)
  2. alertTitle - string: title of the modal
  3. alertText - string: sub text of the modal
  4. title - string: title text of the mail
  5. body - string: body text of the mail

Returns

Promise returns any: adjusted mail result

Example

await this.mailboxService
 .showMailModal(
   this.modalService,
   '_dappcontacts.invitation-message',
   '_dappcontacts.invitation-message-long',
   '_dappcontacts.invitation-text.title',
   '_dappcontacts.invitation-text.body',
 );

raiseMailLoadCount

mailboxService.raiseMailLoadCount(raise, type);

Increase the mail count for a specific type

Parameters

  1. raise - number: number to raise the mail count with
  2. type - string: sent / received

Example

raiseMailLoadCount(3, 'sent')

getMails

mailboxService.getMails();

Load the mails for the current account.

Parameters

  1. options - object: The options used for calling
    • from - string (optional): The address the call “transaction” should be made from
  2. callback - Function (optional): This callback will be fired..
  3. somethingElse - string (optional): this can be set if required, defaults to "latest"

Returns

Promise returns void: resolved when done

{
  receivedMails: [ this.getMail() ],
  sentMails: [ ... ]
}

Example

await mailboxService.getMails();

getMail

mailboxService.getMail(mailId);

Get a mail with a mail id.

Parameters

  1. mailId - string: TThe mail identifier

Returns

Promise returns any: return the mail

{
  "id": "0x00000000000000000000000000000000000000fa",
  "content": {
    "from": "0xe70dfbc43369DE771d357fA4a6559be2eF16772f",
    "fromAlias": "Another user",
    "title": "contact request",
    "body": "hello,\n\ni want to add you as a contact.\n\nWith kind regards,\n\nAnother user",
    "attachments": [
      {
        "type": "commKey",
        "key": "9430..."
      }
    ],
    "sent": 1526626132635,
    "to": "0xCCC..."
  },
  "cryptoInfo": {
    "originator": "0xd926...",
    "keyLength": 256,
    "algorithm": "aes-256-cbc"
  }
}

Example

const mail = this.mailboxService.getMail('0x00')

sendMail

mailboxService.sendMail(mail, from, to);

Send an mail, using the queue.

Parameters

  1. mail - string: mail object
  2. from - string: account id from
  3. to - string: to account id

Returns

Promise returns void: resolved when done

Example

this.mailboxService.sendMail({
  content: {
    sent: new Date().getTime(),
    from: this.myAccountId,
    to: this.mail.content.from,
    title: this.mail.content.title,
    body: this.answer,
  }
}, '0x000', '0x001')

sendAnswer

mailboxService.sendAnswer(mail, from, to);

Send an mail answer, using the queue.

Parameters

  1. mail - string: mail object
  2. from - string: account id from
  3. to - string: to account id

Returns

Promise returns void: resolved when done

Example

this.mailboxService.sendAnswer({
  parentId: this.mailId,
  content: {
    sent: new Date().getTime(),
    from: this.myAccountId,
    to: this.mail.content.from,
    title: this.mail.content.title,
    body: this.answer,
  }
}, '0x000', '0x001')