Reading message

First of all, let’s create messages controller (Inbox folder) for our account:

const { list, dispose } = await ylide.mailbox.inbox([account]);

You must call "dispose" when you don't need this list anymore. That's because messages controller subscribes to the updates (new messages) and will keep updating until you explicitly dispose it.

const message = list.messages[0];

Now, we have all the metadata: date, sender, recipient, key for decryption. But we hadn’t loaded message content from the blockchain yet and hadn't decrypt it. So, let’s do this:

const decrypted = await ylide.mailbox.decrypt(message);

Finally, we can easily access the content of the message:

const { subject, content } = decrypted.content;
// old messages' content is plaintext, new ones are YMF:
const text = typeof content === "string" ? content : content.toPlainText();

alert(decrypted.content.subject + '\n\n' + decrypted.content.content);


Last updated