[8056] | 1 | package pkg.crawler.data.conn; |
---|
| 2 | |
---|
| 3 | import java.util.Properties; |
---|
| 4 | import java.util.concurrent.ScheduledThreadPoolExecutor; |
---|
| 5 | |
---|
| 6 | import javax.mail.Folder; |
---|
| 7 | import javax.mail.MessagingException; |
---|
| 8 | import javax.mail.Session; |
---|
| 9 | |
---|
| 10 | import pkg.crawler.tread.CrawlerThread; |
---|
| 11 | |
---|
| 12 | import com.sun.mail.imap.ACL; |
---|
| 13 | import com.sun.mail.imap.IMAPFolder; |
---|
| 14 | import com.sun.mail.imap.IMAPStore; |
---|
| 15 | import com.sun.mail.imap.Rights; |
---|
| 16 | import com.sun.mail.imap.Rights.Right; |
---|
| 17 | |
---|
| 18 | public class Crawler{ |
---|
| 19 | |
---|
| 20 | private String host; |
---|
| 21 | private String user; |
---|
| 22 | private String password; |
---|
| 23 | private String mbox; |
---|
| 24 | private String hostSolr; |
---|
| 25 | private ACL acl; |
---|
| 26 | |
---|
| 27 | public Crawler(String host, String password, String hostSolr) |
---|
| 28 | { |
---|
| 29 | this.host = host; |
---|
| 30 | this.user = "expresso-admin"; |
---|
| 31 | this.password = password; |
---|
| 32 | this.mbox = "user"; |
---|
| 33 | this.hostSolr = hostSolr; |
---|
| 34 | |
---|
| 35 | //Cria a ACL a ser configurada |
---|
| 36 | acl = new ACL("expresso-admin"); |
---|
| 37 | |
---|
| 38 | //Define direito de leitura |
---|
| 39 | Rights rights = new Rights(); |
---|
| 40 | rights.add(Right.READ); |
---|
| 41 | |
---|
| 42 | //Configura direito de leitura para a ACL |
---|
| 43 | acl.setRights(rights); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | public void run() |
---|
| 48 | { |
---|
| 49 | |
---|
| 50 | int iAux0 = 0; |
---|
| 51 | while (iAux0 == 0) |
---|
| 52 | { |
---|
| 53 | iAux0 = 1; |
---|
| 54 | |
---|
| 55 | //Inicializando as propriedades default da máquina para conexão |
---|
| 56 | //com o servidor IMAP |
---|
| 57 | Properties props = System.getProperties(); |
---|
| 58 | Session session = Session.getInstance(props, null); |
---|
| 59 | |
---|
| 60 | IMAPStore store = new IMAPStore(session, null); |
---|
| 61 | |
---|
| 62 | try { |
---|
| 63 | |
---|
| 64 | //Conectando com o servidor IMAP |
---|
| 65 | store.connect(host, user, password); |
---|
| 66 | //Definindo a pasta base a ser usada |
---|
| 67 | IMAPFolder imapFolder = (IMAPFolder)store.getFolder(mbox); |
---|
| 68 | ScheduledThreadPoolExecutor doAll = new ScheduledThreadPoolExecutor(4); |
---|
| 69 | //Faz a iteração entre os usuários/pastas do usuário |
---|
| 70 | |
---|
| 71 | for (Folder fINBOXAux : imapFolder.list()) |
---|
| 72 | { |
---|
| 73 | System.out.println(fINBOXAux.getFullName()); |
---|
| 74 | try |
---|
| 75 | { |
---|
| 76 | CrawlerThread crawlerThread = new CrawlerThread((IMAPFolder)fINBOXAux, hostSolr); |
---|
| 77 | |
---|
| 78 | doAll.execute(crawlerThread); |
---|
| 79 | |
---|
| 80 | } |
---|
| 81 | catch (Exception e) |
---|
| 82 | { |
---|
| 83 | continue; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | } catch (MessagingException e) { |
---|
| 89 | System.out.println(e.getMessage()); |
---|
| 90 | e.printStackTrace(); |
---|
| 91 | } |
---|
| 92 | catch (Exception e) |
---|
| 93 | { |
---|
| 94 | System.out.println(e.getMessage()); |
---|
| 95 | e.printStackTrace(); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | } |
---|