forked from IF-LK-2020/mymail
Added a bunch of stuff
This commit is contained in:
parent
32bbcb01e1
commit
a1befcdfd5
50
MyMail.java
50
MyMail.java
|
@ -75,8 +75,7 @@ public class MyMail {
|
|||
*/
|
||||
private boolean connectToServer() {
|
||||
// TODO: Connection-Objekt initialisieren
|
||||
con = null;
|
||||
|
||||
con = new Connection(ip, port);
|
||||
// Begrüssungsnachricht des Servers empfangen und prüfen
|
||||
String mes = con.receive();
|
||||
if( mes == null || mes.startsWith("-ERR") ) {
|
||||
|
@ -106,13 +105,24 @@ public class MyMail {
|
|||
* @link https://datatracker.ietf.org/doc/html/rfc1939#page-13
|
||||
*/
|
||||
private boolean login() {
|
||||
String mes = ""; // Speicher für die Antworten des Servers
|
||||
|
||||
|
||||
// TODO: Implementieren
|
||||
// USER Kommando senden und Antwort prüfen
|
||||
con.send("USER " + user);
|
||||
String mes = con.receive(); // Speicher für die Antworten des Servers
|
||||
if(mes == null || mes.startsWith("-ERR") ){
|
||||
lastError = "Fehler beim abfragen des Users!";
|
||||
return false;
|
||||
}
|
||||
|
||||
// PASS Kommando senden und Antwort prüfen
|
||||
|
||||
con.send("Pass " + password);
|
||||
mes = con.receive(); // Speicher für die Antworten des Servers
|
||||
if(mes == null || mes.startsWith("-ERR") ){
|
||||
lastError = "Fehler beim Einloggen!";
|
||||
return false;
|
||||
}
|
||||
// Anmeldung war erfolgreich
|
||||
return true;
|
||||
}
|
||||
|
@ -128,8 +138,7 @@ public class MyMail {
|
|||
* @link https://datatracker.ietf.org/doc/html/rfc1939#page-6
|
||||
*/
|
||||
public int getMessageCount() {
|
||||
String mes = "";
|
||||
|
||||
|
||||
// TODO: Implementieren
|
||||
// Sende den STAT Befehl
|
||||
// Prüfe, ob die Antwort ein Fehler ist
|
||||
|
@ -137,7 +146,15 @@ public class MyMail {
|
|||
// Finde die Leerzeichen mit indexOf(" ")
|
||||
// Ermittele den Text mit substring(von, bis)
|
||||
// Wandele mit Integer.parseInt() in eine Zahl um
|
||||
return 0;
|
||||
//Bei einem Fehler soll -1 zurückgegeben werden und eine
|
||||
//sinnvolle antwort zurückgegeben werden
|
||||
con.send("STAT");
|
||||
String mes = con.receive(); // Speicher für die Antworten des Servers
|
||||
if(mes == null || mes.startsWith("-ERR") ){
|
||||
lastError = "Fehler beim Abfragen der Mails!";
|
||||
return -1;
|
||||
}
|
||||
return Integer.parseInt(mes.substring(4,6));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,12 +176,22 @@ public class MyMail {
|
|||
|
||||
// Anmeldung durchführen und prüfen
|
||||
// Hinweis: Nutze die login() Methode
|
||||
if(!login()){
|
||||
gui.setError(lastError);
|
||||
return;
|
||||
}
|
||||
|
||||
// Anzahl Mails auf dem Server abfragen
|
||||
int mailCount = 0;
|
||||
int mailCount = getMessageCount();
|
||||
if(mailCount <= 0){
|
||||
gui.setError(lastError);
|
||||
return;
|
||||
}
|
||||
|
||||
// Abruf der Mails nach fortlaufender Nummer
|
||||
for( int i = 1; i <= mailCount; i++ ) {
|
||||
|
||||
|
||||
// Mail abrufen (nutze getMail(int))
|
||||
// Mail der GUI hinzufügen (nutze gui.addMailToLost(Mail))
|
||||
}
|
||||
|
@ -196,7 +223,12 @@ public class MyMail {
|
|||
* @return Ein Mail-Objekt oder {@code null}.
|
||||
*/
|
||||
public Mail getMail( int pNumber ) {
|
||||
String mes = ""; // Speicher für Antworten des Servers
|
||||
con.send("RETR " + pNumber);
|
||||
String mes = con.receive(); // Speicher für Antworten des Servers
|
||||
if(mes == null || mes.startsWith("-ERR")){
|
||||
lastError = "Fehler beim abfragen der Mail!";
|
||||
return null;
|
||||
}
|
||||
|
||||
// Prüfen, ob es eine Mail mit der Nummer pNumber gibt
|
||||
|
||||
|
|
|
@ -1,42 +1,78 @@
|
|||
#BlueJ package file
|
||||
dependency1.from=MailClient
|
||||
dependency1.to=Connection
|
||||
dependency1.from=MyMailGUI
|
||||
dependency1.to=MyMail
|
||||
dependency1.type=UsesDependency
|
||||
editor.fx.0.height=777
|
||||
editor.fx.0.width=804
|
||||
editor.fx.0.x=36
|
||||
editor.fx.0.y=23
|
||||
objectbench.height=101
|
||||
objectbench.width=776
|
||||
dependency2.from=MyMailGUI
|
||||
dependency2.to=Mail
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=MyMailGUI
|
||||
dependency3.to=List
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=MyMail
|
||||
dependency4.to=Connection
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=MyMail
|
||||
dependency5.to=MyMailGUI
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=MyMail
|
||||
dependency6.to=Mail
|
||||
dependency6.type=UsesDependency
|
||||
editor.fx.0.height=1017
|
||||
editor.fx.0.width=914
|
||||
editor.fx.0.x=771
|
||||
editor.fx.0.y=0
|
||||
objectbench.height=93
|
||||
objectbench.width=1656
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8007380073800738
|
||||
package.editor.height=427
|
||||
package.editor.width=662
|
||||
package.editor.x=40
|
||||
package.editor.y=172
|
||||
package.frame.height=600
|
||||
package.frame.width=800
|
||||
package.numDependencies=1
|
||||
package.numTargets=2
|
||||
package.divider.vertical=0.8920086393088553
|
||||
package.editor.height=819
|
||||
package.editor.width=1545
|
||||
package.editor.x=0
|
||||
package.editor.y=0
|
||||
package.frame.height=1026
|
||||
package.frame.width=1696
|
||||
package.numDependencies=6
|
||||
package.numTargets=5
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
readme.height=58
|
||||
readme.height=60
|
||||
readme.name=@README
|
||||
readme.width=47
|
||||
readme.width=49
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=50
|
||||
target1.name=Connection
|
||||
target1.height=70
|
||||
target1.name=MyMail
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=90
|
||||
target1.x=350
|
||||
target1.y=40
|
||||
target2.height=50
|
||||
target2.name=MailClient
|
||||
target1.width=120
|
||||
target1.x=140
|
||||
target1.y=10
|
||||
target2.height=70
|
||||
target2.name=Mail
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=80
|
||||
target2.x=110
|
||||
target2.y=150
|
||||
target2.width=120
|
||||
target2.x=330
|
||||
target2.y=460
|
||||
target3.height=50
|
||||
target3.name=Connection
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=100
|
||||
target3.x=520
|
||||
target3.y=150
|
||||
target4.height=70
|
||||
target4.name=List
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=150
|
||||
target4.x=490
|
||||
target4.y=270
|
||||
target5.height=70
|
||||
target5.name=MyMailGUI
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.width=120
|
||||
target5.x=50
|
||||
target5.y=330
|
||||
|
|
Loading…
Reference in New Issue