User Created Folders
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nagendra_Barla
Posted On:   Thursday, January 2, 2003 02:31 AM


How to create and retrieve Folders from imap server using JavaMail?

I tried with the help of list() of the "Folder" class after creating.But when i try to retrieve it is returning all the junk(User Folders + System Folders).

Is there any way to identify user created folders?

Suggestion Pleassssssssssssssse

Re: User Created Folders

Posted By:   Anonymous  
Posted On:   Saturday, January 11, 2003 01:18 PM

Try this:


import javax.mail.*;
import java.io.*;
import java.util.*;

public class listaCorreio{
public static void listar(String Usuario, String Senha, String servidorIMAP)
throws IOException, MessagingException, NoSuchProviderException, Exception {
Store store = null;
Session session = null;
Folder folder = null;

//Obtem o objeto Properties
java.util.Properties properties = System.getProperties();
properties.put("mail.imap.host", servidorIMAP);
//Obtem o objeto Session
session = Session.getInstance(properties, null);
session.setDebug(false);
//Obtem o objeto Store
store = session.getStore("imap");
if (servidorIMAP == null || Usuario == null || Senha == null) throw new java.lang.Exception("Servidor, Usuário e/ou Senha não existentes ou incorretos");
store.connect(servidorIMAP, Usuario, Senha);
if ((folder = store.getDefaultFolder()) == null) throw new Exception("Não existe diretório padrão.");
listarInformacoesDoDiretorio(folder, "");
if((folder.getType() & Folder.HOLDS_FOLDERS) != 0){
Folder [] subfolder = folder.list();
for(int folderNum = 0; folderNum < subfolder.length; folderNum++)
listarInformacoesDoDiretorio(subfolder[folderNum], " ");
}
store.close();
}

public static void listarInformacoesDoDiretorio(Folder folder, String tab)
throws MessagingException {
if(folder.isSubscribed() || folder.getName().equals("INBOX")){
System.out.println(tab + folder.getName());
if((folder.getType() & Folder.HOLDS_MESSAGES) != 0){
System.out.println(tab + " " + "Total de Mensagens : " + folder.getMessageCount());
System.out.println(tab + " " + "Mensagens Novas : " + folder.getNewMessageCount());
System.out.println(tab + " " + "Mensagens Não Lidas: " + folder.getUnreadMessageCount());
System.out.println(tab + " " + "Mensagens Lidas : " + (folder.getMessageCount() - folder.getNewMessageCount() - folder.getUnreadMessageCount()));
}
if((folder.getType() & Folder.HOLDS_FOLDERS) != 0){
Folder [] subfolder = folder.list();
for(int folderNum = 0; folderNum < subfolder.length; folderNum++)
listarInformacoesDoDiretorio(subfolder[folderNum], tab + " ");
}
}
}

public static void main(String [] args){
try{
listar(args[0],args[1],args[2]);
}catch(IOException ioe){
}catch(MessagingException me){
}catch(Exception e){
}
}
}
About | Sitemap | Contact