public static int removeEmails(Account account, String protocol) throws MessagingException, UnknownHostException { int count = 0; Session session = Session.getInstance( Protocol.POP3.equals(protocol) ? getPop3MailProperties(account) : getImapMailProperties(account)); Folder inbox; // store = session.getStore("imap"); if (account.getLoginName().contains("@yahoo.")) { IMAPStore imapstore = (IMAPStore) session.getStore(protocol); yahooConnect(account, imapstore, true); inbox = imapstore.getFolder("INBOX"); } else { Store store = session.getStore(protocol); store.connect(account.getReceiveHost(), account.getLoginName(), account.getPassword()); inbox = store.getFolder("INBOX"); } inbox.open(Folder.READ_WRITE); count = inbox.getMessageCount(); for (Message message : inbox.getMessages()) { message.setFlag(Flags.Flag.DELETED, true); } inbox.close(true); return count; }
/** * Special Yahoo connect routines. We resolve hostname IP address and try each one until connected * * @param account * @param store * @return * @throws java.net.UnknownHostException */ private static int yahooConnect( Account account, IMAPStore store, boolean specialYahooConnectEnabled) throws UnknownHostException, MessagingException { int connectionAttempts = 0; store.SetIDCommand( "ID (\"vendor\" \"Zimbra\" \"os\" \"Windows XP\" \"os-version\" \"5.1\" \"guid\" \"4062-5711-9195-4050\")"); if (specialYahooConnectEnabled) { InetAddress[] addresses = InetAddress.getAllByName(account.getReceiveHost()); for (InetAddress address : addresses) { try { store.connect(address.getHostAddress(), account.getLoginName(), account.getPassword()); connectionAttempts++; break; } catch (Throwable t) { } } } else { store.connect(account.getReceiveHost(), account.getLoginName(), account.getPassword()); connectionAttempts++; } return connectionAttempts; }
public static void main(String[] args) throws MessagingException, NamingException, IOException, InterruptedException { Account account = new Account(); // account.setLoginName("*****@*****.**"); // account.setPassword("p123456"); // account.setReceiveHost("imap.aol.com"); // account.setReceivePort("143"); // removeEmails(account, "imap"); // account.setLoginName("*****@*****.**"); // account.setPassword("123456"); // account.setReceiveHost("pop3.live.com"); // account.setReceiveTs("ssl"); // account.setReceivePort("995"); // // removeEmails(account, "pop3"); account.setLoginName("*****@*****.**"); account.setPassword("123456"); account.setReceiveHost("imap.mail.yahoo.com"); account.setReceivePort("143"); removeEmails(account, "imap"); // account.setLoginName("*****@*****.**"); // account.setPassword("passw0rd"); // account.setReceiveHost("pop.gmail.com"); // account.setReceiveTs("ssl"); // account.setReceivePort("995"); // removeEmails(account, "pop3"); // account.setLoginName("*****@*****.**"); // account.setPassword("passw0rd"); // account.setReceiveHost("imap.gmail.com"); // account.setReceiveTs("ssl"); // account.setReceivePort("993"); // removeEmails(account, "imap"); // account.setLoginName("*****@*****.**"); // account.setPassword("123456"); // account.setReceiveHost("pop.emailsrvr.com"); // account.setReceivePort("110"); // removeEmails(account, "pop3"); // account.setLoginName("*****@*****.**"); // account.setPassword("123456"); // account.setReceiveHost("pop.emailsrvr.com"); // account.setReceivePort("110"); // removeEmails(account, "pop3"); sendBigEmail(account.getLoginName()); Thread.sleep(60000); sendSimpleEmails(account.getLoginName(), 3); sendSimpleEmails(account.getLoginName(), 5); }
public void notifyAccountLock(Account account, String context) { PartnerCode partnerCode = account.getPartnerCode(); String lockedOutMessageBody = SysConfigManager.instance() .getValue("lockedOutMessageBody", LOCKED_OUT_MESSAGE_BODY, partnerCode); String lockedOutMessageSubject = SysConfigManager.instance() .getValue("lockedOutMessageSubject", LOCKED_OUT_MESSAGE_SUBJECT, partnerCode); String lockedOutMessageFrom = SysConfigManager.instance() .getValue("lockedOutMessageFrom", LOCKED_OUT_MESSAGE_FROM, partnerCode); String lockedOutMessageAlias = SysConfigManager.instance() .getValue("lockedOutMessageAlias", LOCKED_OUT_MESSAGE_ALIAS, partnerCode); try { Email email = new Email(); email.setSubject(lockedOutMessageSubject); email.setStatus("0"); email.setUserId(account.getUser_id()); email.setMessage_type("EMAIL"); email.setFrom(lockedOutMessageFrom); email.setFrom_alias(lockedOutMessageAlias); email.setTo(account.getLoginName()); email.setBodySize(lockedOutMessageBody.length()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); email.setMaildate(dateFormat.format(new Date(System.currentTimeMillis()))); // ugh! email.setOriginal_account(account.getLoginName()); // create the pojgo EmailPojo emailPojo = new EmailPojo(); emailPojo.setEmail(email); Body body = new Body(); body.setData(lockedOutMessageBody.getBytes()); // note, the email will be encoded to prevent sql-injection. since this email is destined // directly for the // device, we need to reverse the encoding after the call to newSaveEmail new EmailRecievedService().newSaveEmail(account, email, body); // Added by Dan so we stop checking accounts that have incorrect passwords account.setStatus("0"); } catch (Throwable t) { log.warn(String.format("failed to save locked out message for %s", context), t); } }
protected int getMessageSize(Message message, Account account) throws IOException, MessagingException { int count = 0; if (account.getLoginName().contains("aol.com") && message.getContent() instanceof Multipart) { Multipart multipart = (Multipart) message.getContent(); for (int i = 0; i < multipart.getCount(); i++) { count += multipart.getBodyPart(i).getSize(); } } else { count = message.getSize(); } return count; }