From f712bcad7b202abac7fa65b4f5a6f3767a14e25e Mon Sep 17 00:00:00 2001 From: Shadab Mehdi Date: Sun, 31 Jan 2016 02:08:05 +0530 Subject: [PATCH] Updated KumarAsshole.java --- java/KumarAsshole.java | 72 +++++++++++++++++++++++++++++++ java/Kumar_asshole.java | 95 ----------------------------------------- 2 files changed, 72 insertions(+), 95 deletions(-) create mode 100644 java/KumarAsshole.java delete mode 100644 java/Kumar_asshole.java diff --git a/java/KumarAsshole.java b/java/KumarAsshole.java new file mode 100644 index 0000000..645a85d --- /dev/null +++ b/java/KumarAsshole.java @@ -0,0 +1,72 @@ + +import java.util.*; +import java.util.regex.*; + +import javax.mail.*; +import javax.mail.internet.*; +import javax.mail.search.FlagTerm; + +public class KumarAsshole { + + public static void main(String[] args) { + KumarAsshole kAsshole = new KumarAsshole(); + kAsshole.read(); + } + + public void read() { + Properties props = new Properties(); + String host = "smtp.gmail.com"; + String username = "yourmailaddress@example.com goes here"; + String password = "your password goes here "; + String Kumar_mail = "the mail address to be replied to !"; + + try { + + Session session = Session.getDefaultInstance(props, null); + Store store = session.getStore("imaps"); + store.connect(host, username, password); + + Folder inbox = store.getFolder("inbox"); + inbox.open(Folder.READ_ONLY); + + Message messages[] = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); + + for (int i = 0; i < messages.length; i++) { + + if (messages[i].getFrom()[0].toString().contains(Kumar_mail)) { + String bodytext = null; + Object content = messages[i].getContent(); + if (content instanceof String) { + bodytext = (String) content; + } else if (content instanceof Multipart) { + Multipart mp = (Multipart) content; + BodyPart bp = mp.getBodyPart(mp.getCount() - 1); + bodytext = (String) bp.getContent(); + } + + Pattern pattern = Pattern.compile("sorry|help|wrong", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(bodytext); + + if (matcher.find()) { + Address[] addressess; + MimeMessage msg = new MimeMessage(session); + msg.setFrom(new InternetAddress(username)); + addressess = messages[i].getFrom(); + String t1 = addressess[0].toString(); + msg.addRecipient(Message.RecipientType.TO, new InternetAddress(t1)); + msg.setSubject("Database fixes"); + msg.setText("No problem. I've fixed it. \n\n Please be careful next time."); + Transport t = null; + t = session.getTransport("smtps"); + t.connect(host, username, password); + t.sendMessage(msg, msg.getAllRecipients()); + } + } + } + inbox.close(true); + store.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/java/Kumar_asshole.java b/java/Kumar_asshole.java deleted file mode 100644 index cd94ce1..0000000 --- a/java/Kumar_asshole.java +++ /dev/null @@ -1,95 +0,0 @@ - -import java.io.File; -import java.io.FileInputStream; -import java.util.*; -import java.util.regex.*; - -import javax.mail.*; -import javax.mail.internet.*; -import javax.mail.search.FlagTerm; -//Dependencies- Java mail API - -public class Kumar_Asshole { - - public static void main(String[] args) { - Kumar_Asshole gmail = new Kumar_Asshole(); - gmail.read(); - } - - public void read() { - Properties props = new Properties(); - - - //modify below properties to your details - String host = "smtp.gmail.com"; - String username = "yourmailaddress@example.com goes here"; - String password = "your password goes here "; - String Kumar_mail = "the mail address to be replied to !"; - - try { - - Session session = Session.getDefaultInstance(props, null); - - Store store = session.getStore("imaps"); - store.connect(host, username, password); - - Folder inbox = store.getFolder("inbox"); - inbox.open(Folder.READ_ONLY); - - Message messages[] = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); - - for (int i = 0; i < messages.length; i++) { - - if (messages[i].getFrom()[0].toString().contains(Kumar_mail)) { - - String bodytext = null; - Object content = messages[i].getContent(); - if (content instanceof String) { - bodytext = (String) content; - - } else if (content instanceof Multipart) { - - Multipart mp = (Multipart) content; - - BodyPart bp = mp.getBodyPart(mp.getCount() - 1); - bodytext = (String) bp.getContent(); - - } - - Pattern pattern = Pattern.compile("sorry|help|wrong", Pattern.CASE_INSENSITIVE); - Matcher matcher = pattern.matcher(bodytext); - // check all occurance - - if (matcher.find()) { - - Properties props1 = new Properties(); - Address[] tomail; - - MimeMessage msg = new MimeMessage(session); - msg.setFrom(new InternetAddress(username)); - tomail = messages[i].getFrom(); - String t1 = tomail[0].toString(); - msg.addRecipient(Message.RecipientType.TO, new InternetAddress(t1)); - msg.setSubject("Database fixes"); - msg.setText("No problem. I've fixed it. \n\n Please be careful next time."); - Transport t = null; - t = session.getTransport("smtps"); - t.connect(host, username, password); - t.sendMessage(msg, msg.getAllRecipients()); - - - } - - - } - } - inbox.close(true); - store.close(); - - }catch(Exception e) - { - - e.printStackTrace(); - } - } -} \ No newline at end of file