From b2e7a335e7fb8fdba5e3fa58dab0e84cd4538b6f Mon Sep 17 00:00:00 2001 From: syedautherabbas Date: Sun, 24 Jan 2016 19:35:55 +0530 Subject: [PATCH 1/4] Java version of Kumar_asshole.sh --- java/Kumar_Asshole.java | 144 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 java/Kumar_Asshole.java diff --git a/java/Kumar_Asshole.java b/java/Kumar_Asshole.java new file mode 100644 index 0000000..8d95da7 --- /dev/null +++ b/java/Kumar_Asshole.java @@ -0,0 +1,144 @@ + +import java.io.File; +import java.io.FileInputStream; +import java.util.*; + +import javax.mail.*; +import javax.mail.internet.*; +import javax.mail.search.FlagTerm; + +/* Before running: + U need to add Javax Mail JAR. +*/ + +public class Kumar_Asshole { + + public static void main(String[] args) { + Kumar_Asshole asshole = new Kumar_Asshole(); + gmail.read_and_reply(); + } + + public void read_and_reply() { + Properties props = new Properties(); +//change the below properties to configure your own. + 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()) { + + Properties props1 = new Properties(); + Address[] tomail; + + MimeMessage msg = new MimeMessage(session); + + try { + msg.setFrom(new InternetAddress(username)); + } catch (MessagingException e1) { + + e1.printStackTrace(); + } + + try { + tomail = messages[i].getFrom(); + String t1 = tomail[0].toString(); + + msg.addRecipient(Message.RecipientType.TO, new InternetAddress(t1)); + } catch (AddressException e1) { + + e1.printStackTrace(); + } catch (MessagingException e1) { + + e1.printStackTrace(); + } + + + try { + msg.setSubject("Database fixes"); + } catch (MessagingException e1) { + + e1.printStackTrace(); + } + + + try { + msg.setText("No problem. I've fixed it. \n\n Please be careful next time."); + + } catch (MessagingException e1) { + + e1.printStackTrace(); + } + + Transport t = null; + try { + + t = session.getTransport("smtps"); + } catch (NoSuchProviderException e) { + + e.printStackTrace(); + } + try { + try { + t.connect(host, username, password); + } catch (MessagingException e) { + + e.printStackTrace(); + } + + t.sendMessage(msg, msg.getAllRecipients()); + } catch (MessagingException e) { + + e.printStackTrace(); + + } finally { + } + } + + } + + } + inbox.close(true); + store.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file From ac58a6f8890ccdb209054b56f2268caa5171e602 Mon Sep 17 00:00:00 2001 From: syedautherabbas Date: Sun, 24 Jan 2016 20:12:28 +0530 Subject: [PATCH 2/4] Signed-off-by: syedautherabbas --- java/Kumar_Asshole.java | 112 +++++++++++----------------------------- 1 file changed, 31 insertions(+), 81 deletions(-) diff --git a/java/Kumar_Asshole.java b/java/Kumar_Asshole.java index 8d95da7..fbdf7b0 100644 --- a/java/Kumar_Asshole.java +++ b/java/Kumar_Asshole.java @@ -2,29 +2,29 @@ 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; -/* Before running: - U need to add Javax Mail JAR. -*/ - public class Kumar_Asshole { public static void main(String[] args) { - Kumar_Asshole asshole = new Kumar_Asshole(); - gmail.read_and_reply(); + Kumar_Asshole gmail = new Kumar_Asshole(); + gmail.read(); } - public void read_and_reply() { + public void read() { Properties props = new Properties(); -//change the below properties to configure your own. - 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 !"; + + + + 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); @@ -42,9 +42,7 @@ public class Kumar_Asshole { if (messages[i].getFrom()[0].toString().contains(Kumar_mail)) { String bodytext = null; - Object content = messages[i].getContent(); - if (content instanceof String) { bodytext = (String) content; @@ -59,7 +57,7 @@ public class Kumar_Asshole { Pattern pattern = Pattern.compile("sorry|help|wrong", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(bodytext); - + // check all occurance if (matcher.find()) { @@ -67,78 +65,30 @@ public class Kumar_Asshole { Address[] tomail; MimeMessage msg = new MimeMessage(session); - - try { - msg.setFrom(new InternetAddress(username)); - } catch (MessagingException e1) { - - e1.printStackTrace(); - } - - try { - tomail = messages[i].getFrom(); - String t1 = tomail[0].toString(); - - msg.addRecipient(Message.RecipientType.TO, new InternetAddress(t1)); - } catch (AddressException e1) { - - e1.printStackTrace(); - } catch (MessagingException e1) { - - e1.printStackTrace(); - } - - - try { - msg.setSubject("Database fixes"); - } catch (MessagingException e1) { - - e1.printStackTrace(); - } - - - try { - msg.setText("No problem. I've fixed it. \n\n Please be careful next time."); - - } catch (MessagingException e1) { - - e1.printStackTrace(); - } - + 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; - try { - - t = session.getTransport("smtps"); - } catch (NoSuchProviderException e) { - - e.printStackTrace(); - } - try { - try { - t.connect(host, username, password); - } catch (MessagingException e) { - - e.printStackTrace(); - } - - t.sendMessage(msg, msg.getAllRecipients()); - } catch (MessagingException e) { - - e.printStackTrace(); - - } finally { - } - } - - } - + t = session.getTransport("smtps"); + t.connect(host, username, password); + t.sendMessage(msg, msg.getAllRecipients()); + + } + + + } + } inbox.close(true); store.close(); - } catch (Exception e) { + }catch(Exception e) + { + e.printStackTrace(); } } - } \ No newline at end of file From 738881ffb9b4d6e0ac42f1fe50ea3d7a13c64e0e Mon Sep 17 00:00:00 2001 From: syedautherabbas Date: Sun, 24 Jan 2016 20:14:43 +0530 Subject: [PATCH 3/4] Java version of Kumar_asshole.sh --- java/Kumar_Asshole.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/Kumar_Asshole.java b/java/Kumar_Asshole.java index fbdf7b0..4f296c9 100644 --- a/java/Kumar_Asshole.java +++ b/java/Kumar_Asshole.java @@ -19,7 +19,7 @@ public class Kumar_Asshole { 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 "; From f66db39b3c7ee6df4f736f0bd807211c6b1bc494 Mon Sep 17 00:00:00 2001 From: syedautherabbas Date: Wed, 27 Jan 2016 22:49:01 +0530 Subject: [PATCH 4/4] Added Kumar_Asshole.java Java version of Kumar_asshole.sh --- java/Kumar_Asshole.java | 115 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/java/Kumar_Asshole.java b/java/Kumar_Asshole.java index 4f296c9..3e3f227 100644 --- a/java/Kumar_Asshole.java +++ b/java/Kumar_Asshole.java @@ -2,12 +2,16 @@ import java.io.File; import java.io.FileInputStream; import java.util.*; +<<<<<<< HEAD import java.util.regex.*; +======= +>>>>>>> b2e7a33... Java version of Kumar_asshole.sh import javax.mail.*; import javax.mail.internet.*; import javax.mail.search.FlagTerm; +<<<<<<< HEAD public class Kumar_Asshole { public static void main(String[] args) { @@ -19,12 +23,36 @@ public class Kumar_Asshole { Properties props = new Properties(); +<<<<<<< HEAD //modify below properties to your details +======= + +>>>>>>> ac58a6f... Signed-off-by: syedautherabbas 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 !"; +======= +/* Before running: + U need to add Javax Mail JAR. +*/ + +public class Kumar_Asshole { + + public static void main(String[] args) { + Kumar_Asshole asshole = new Kumar_Asshole(); + gmail.read_and_reply(); + } + + public void read_and_reply() { + Properties props = new Properties(); +//change the below properties to configure your own. + 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 !"; +>>>>>>> b2e7a33... Java version of Kumar_asshole.sh try { Session session = Session.getDefaultInstance(props, null); @@ -42,7 +70,13 @@ public class Kumar_Asshole { if (messages[i].getFrom()[0].toString().contains(Kumar_mail)) { String bodytext = null; +<<<<<<< HEAD Object content = messages[i].getContent(); +======= + + Object content = messages[i].getContent(); + +>>>>>>> b2e7a33... Java version of Kumar_asshole.sh if (content instanceof String) { bodytext = (String) content; @@ -57,7 +91,11 @@ public class Kumar_Asshole { Pattern pattern = Pattern.compile("sorry|help|wrong", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(bodytext); +<<<<<<< HEAD // check all occurance +======= + +>>>>>>> b2e7a33... Java version of Kumar_asshole.sh if (matcher.find()) { @@ -65,6 +103,7 @@ public class Kumar_Asshole { Address[] tomail; MimeMessage msg = new MimeMessage(session); +<<<<<<< HEAD msg.setFrom(new InternetAddress(username)); tomail = messages[i].getFrom(); String t1 = tomail[0].toString(); @@ -91,4 +130,80 @@ public class Kumar_Asshole { e.printStackTrace(); } } +======= + + try { + msg.setFrom(new InternetAddress(username)); + } catch (MessagingException e1) { + + e1.printStackTrace(); + } + + try { + tomail = messages[i].getFrom(); + String t1 = tomail[0].toString(); + + msg.addRecipient(Message.RecipientType.TO, new InternetAddress(t1)); + } catch (AddressException e1) { + + e1.printStackTrace(); + } catch (MessagingException e1) { + + e1.printStackTrace(); + } + + + try { + msg.setSubject("Database fixes"); + } catch (MessagingException e1) { + + e1.printStackTrace(); + } + + + try { + msg.setText("No problem. I've fixed it. \n\n Please be careful next time."); + + } catch (MessagingException e1) { + + e1.printStackTrace(); + } + + Transport t = null; + try { + + t = session.getTransport("smtps"); + } catch (NoSuchProviderException e) { + + e.printStackTrace(); + } + try { + try { + t.connect(host, username, password); + } catch (MessagingException e) { + + e.printStackTrace(); + } + + t.sendMessage(msg, msg.getAllRecipients()); + } catch (MessagingException e) { + + e.printStackTrace(); + + } finally { + } + } + + } + + } + inbox.close(true); + store.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +>>>>>>> b2e7a33... Java version of Kumar_asshole.sh } \ No newline at end of file