I want to know if are any way to get all the unread messages, actually i only see a function called getUnreadMessageCount() but i don’t know if a message is read or not
you can use the search method for that…
And how can i mark a mail as read?
using the message’s setFlag method
But with the setFlag i can mark a message as read? in the properties of Message? a piece of code pelase? thanks for all
out of my head:
message.setFlag(“READ”)
message.setFlag(‘SEEN’, true);
Thanks, Patrick
But when i get the message is a plugins.mail.MailMessage and don’t have any set option, only get.
This is my code:
// Registramos e l plugin
plugins.MailPro.register("Penta MSI", "UKs2EWEQUOfnNo7N05vcQqatPPE1wI8J3VLIWnAgWp7zO/NZtrnW9A==");
application.output(plugins.MailPro.getVersion());
// Creamos una conexión a la cuenta imap
var account = plugins.MailPro.ImapAccount("Connection");
// Le pasamos los parámetros
account.host = "xxx.xxx.xx.x";
account.userName = "username";
account.password = "password";
account.useSSL = true;
account.port = 993;
// Nos conectamos
account.connect();
// Obtenemos la carpeta deseada
var folder = account.getFolder("pendientes");
// La abrimos
folder.openFolder();
// Comprobamos si hay mensajes sin leer
if (folder.getUnreadMessageCount() > 0) {
// Obtenemos los mensajes sin leer
/**@type {Array<plugins.mail.MailMessage>}*/
var messages = folder.search(4, "SEEN", false);
// Recorremos los mensajes
for (var i = 0; i < messages.length; i++) {
// Obtenemos la cantidad de archivos adjuntos
var attachments = messages[i].getAttachments();
// Comprobamos si tiene archivos adjuntos
if (attachments.length) {
// Si encontramos ficheros adjuntos los recorremos
for (var j = 0, attachmentsLength = attachments.length; j < attachmentsLength; j++) {
// Obtenemos el contenido del fichero
var fileData = attachments[j].getData();
// Creamos un fichero con el mismo nombre
var f = plugins.file.createFile(attachments[j].getName());
f.createNewFile();
// Le añadimos el contenido
f.setBytes(fileData);
// Subimos el fichero al servidor
subirArchivo(f);
}
}
}
}
// Desconectamos de la cuenta
account.disconnect();
And odn’t know in what time set the flag, any idea?
how about
messages*.setFlag(‘SEEN’, true);*
?? You only get an array of messages and never have a single message in any variable?
For the moment i don’t put the message in any variable, because accesing with the array position is fine. By other case when i put messages*. don’t appear the setFlag function, is anything wrong?*