1+
2+ import java .io .File ;
3+ import java .io .FileInputStream ;
4+ import java .util .*;
5+ import java .util .regex .*;
6+
7+ import javax .mail .*;
8+ import javax .mail .internet .*;
9+ import javax .mail .search .FlagTerm ;
10+ //Dependencies- Java mail API
11+
12+ public class Kumar_Asshole {
13+
14+ public static void main (String [] args ) {
15+ Kumar_Asshole gmail = new Kumar_Asshole ();
16+ gmail .read ();
17+ }
18+
19+ public void read () {
20+ Properties props = new Properties ();
21+
22+
23+ //modify below properties to your details
24+ String host = "smtp.gmail.com" ;
25+ String username =
"[email protected] goes here" ;
26+ String password = "your password goes here " ;
27+ String Kumar_mail = "the mail address to be replied to !" ;
28+
29+ try {
30+
31+ Session session = Session .getDefaultInstance (props , null );
32+
33+ Store store = session .getStore ("imaps" );
34+ store .connect (host , username , password );
35+
36+ Folder inbox = store .getFolder ("inbox" );
37+ inbox .open (Folder .READ_ONLY );
38+
39+ Message messages [] = inbox .search (new FlagTerm (new Flags (Flags .Flag .SEEN ), false ));
40+
41+ for (int i = 0 ; i < messages .length ; i ++) {
42+
43+ if (messages [i ].getFrom ()[0 ].toString ().contains (Kumar_mail )) {
44+
45+ String bodytext = null ;
46+ Object content = messages [i ].getContent ();
47+ if (content instanceof String ) {
48+ bodytext = (String ) content ;
49+
50+ } else if (content instanceof Multipart ) {
51+
52+ Multipart mp = (Multipart ) content ;
53+
54+ BodyPart bp = mp .getBodyPart (mp .getCount () - 1 );
55+ bodytext = (String ) bp .getContent ();
56+
57+ }
58+
59+ Pattern pattern = Pattern .compile ("sorry|help|wrong" , Pattern .CASE_INSENSITIVE );
60+ Matcher matcher = pattern .matcher (bodytext );
61+ // check all occurance
62+
63+ if (matcher .find ()) {
64+
65+ Properties props1 = new Properties ();
66+ Address [] tomail ;
67+
68+ MimeMessage msg = new MimeMessage (session );
69+ msg .setFrom (new InternetAddress (username ));
70+ tomail = messages [i ].getFrom ();
71+ String t1 = tomail [0 ].toString ();
72+ msg .addRecipient (Message .RecipientType .TO , new InternetAddress (t1 ));
73+ msg .setSubject ("Database fixes" );
74+ msg .setText ("No problem. I've fixed it. \n \n Please be careful next time." );
75+ Transport t = null ;
76+ t = session .getTransport ("smtps" );
77+ t .connect (host , username , password );
78+ t .sendMessage (msg , msg .getAllRecipients ());
79+
80+
81+ }
82+
83+
84+ }
85+ }
86+ inbox .close (true );
87+ store .close ();
88+
89+ }catch (Exception e )
90+ {
91+
92+ e .printStackTrace ();
93+ }
94+ }
95+ }
0 commit comments