Repository navigation
Expand file tree
/
Copy pathMailReader.java
More file actions
122 lines (92 loc) · 3.41 KB
/
Copy pathMailReader.java
File metadata and controls
122 lines (92 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import java.util.ArrayList;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
/*
Class that will check a specified email box for replies to the total recall system.
*/
public class MailReader {
static int howManyMessages = 0;
static ArrayList<String> myMessages = new ArrayList<String>();
static String reply = null;
public static boolean searchForPhone(String phone){
CharSequence phoneN = phone;
for(int i=0;i<myMessages.size();i++){
return myMessages.get(i).contains(phone);
}
return false;
}
public static String getReply(String phone){
for(int i=0;i<myMessages.size();i++){
if(myMessages.get(i).contains(phone)){
reply = myMessages.get(i).toString();
reply = reply.substring(26);
System.out.println(reply);
return reply;
}
else{
return "no reply yet!";
}
}
return "no reply yet!";
}
public static int checkHowMany() {
return howManyMessages;
}
public static void check(String host, String storeType, String user,
String password)
{
try {
// create properties field
Properties properties = new Properties();
properties.put("mail.pop3s.host", host);
properties.put("mail.pop3s.port", "995");
properties.put("mail.pop3s.starttls.enable", "true");
// Setup authentication, get session
Session emailSession = Session.getInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"totalrecallaf@gmail.com", "equine2449");
}
});
// emailSession.setDebug(true);
// create the POP3 store object and connect with the pop server
Store store = emailSession.getStore("pop3s");
store.connect();
// create the folder object and open it
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_WRITE);
// retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);
howManyMessages = messages.length;
for (int i = 0, n = messages.length; i < n; i++) {
Message message = messages[i];
myMessages.add(message.getContent().toString());
System.err.println(myMessages.get(i));
}
// close the store and folder objects
emailFolder.close(false);
store.close();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String host = "pop.gmail.com";// change accordingly
String mailStoreType = "pop3";
String username = "totalrecallaf@gmail.com";// change accordingly
String password = "equine2449";// change accordingly
check(host, mailStoreType, username, password);
}
}