forked from IF-LK-2020/mymail
Mail lesbar
This commit is contained in:
parent
8559a71959
commit
7f83467a07
41
MyMail.java
41
MyMail.java
|
@ -1,3 +1,5 @@
|
|||
import java.util.Iterator;
|
||||
|
||||
public class MyMail {
|
||||
|
||||
public static final String POP3_SERVER = "127.0.0.1";
|
||||
|
@ -47,7 +49,7 @@ public class MyMail {
|
|||
// GUI erstellen und Status setzen.
|
||||
gui = new MyMailGUI(this);
|
||||
gui.setStatus("App gestartet");
|
||||
|
||||
|
||||
getAllMails();
|
||||
}
|
||||
|
||||
|
@ -219,7 +221,7 @@ public class MyMail {
|
|||
*/
|
||||
public Mail getMail(int pNumber) {
|
||||
String mes = ""; // Speicher für Antworten des Servers
|
||||
|
||||
|
||||
// Prüfen, ob es eine Mail mit der Nummer pNumber gibt
|
||||
int count = getMessageCount();
|
||||
if (pNumber > count) {
|
||||
|
@ -229,7 +231,13 @@ public class MyMail {
|
|||
// Mail abrufen (RETR)
|
||||
con.send("RETR " + pNumber);
|
||||
mes = con.receive();
|
||||
|
||||
boolean header = true;
|
||||
String date = "";
|
||||
String sender = "";
|
||||
String subject = "";
|
||||
String text = "";
|
||||
|
||||
while (!mes.equals(".")) {
|
||||
// Text der Mail parsen
|
||||
// Verarbeite die Metadaten, vor allem:
|
||||
|
@ -243,10 +251,35 @@ public class MyMail {
|
|||
// machen.
|
||||
// Tipp: Merk dir in einem boolean, ob du im Textkörper oder im Header bist.
|
||||
mes = con.receive();
|
||||
text += mes;
|
||||
if (header) {
|
||||
if (mes.equals("")) {
|
||||
header = false;
|
||||
} else if (mes.startsWith("Delivery-date")) {
|
||||
date = mes.substring(15);
|
||||
} else if (mes.startsWith("From")) {
|
||||
boolean open = false;
|
||||
for (char c : mes.toCharArray()) {
|
||||
if (open) {
|
||||
if (c == '>')
|
||||
break;
|
||||
sender += c;
|
||||
} else if (c == '<') {
|
||||
open = true;
|
||||
}
|
||||
}
|
||||
} else if (mes.startsWith("Subject")) {
|
||||
subject = mes.substring(9);
|
||||
}
|
||||
} else {
|
||||
mes = mes.replaceAll("=C3=BC", "ü");
|
||||
mes = mes.replaceAll("=C3=A4", "ä");
|
||||
mes = mes.replaceAll("=C3=B6", "ö");
|
||||
mes = mes.replaceAll("=C3=9F", "ß");
|
||||
text += mes + "\n";
|
||||
}
|
||||
} // end of while
|
||||
|
||||
return new Mail(pNumber, "DATE", "SENDER", "SUBJECT", mes);
|
||||
return new Mail(pNumber, date, sender, subject, text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue