forked from IF-LK-2020/mymail
Compare commits
4 Commits
7f83467a07
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc2fa40bcd | ||
|
|
c035137020 | ||
|
|
ddf81f11aa | ||
|
|
587beb098c |
98
LoginGUI.java
Normal file
98
LoginGUI.java
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPasswordField;
|
||||||
|
|
||||||
|
public class LoginGUI extends JDialog implements ActionListener {
|
||||||
|
|
||||||
|
private MyMail app;
|
||||||
|
|
||||||
|
private final JPanel contentPanel = new JPanel();
|
||||||
|
private JTextField address;
|
||||||
|
private JTextField user;
|
||||||
|
private JPasswordField pw;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch the application.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the dialog.
|
||||||
|
*/
|
||||||
|
public LoginGUI(MyMail app) {
|
||||||
|
this.app = app;
|
||||||
|
setTitle("Login");
|
||||||
|
setBounds(100, 100, 251, 220);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
getContentPane().setLayout(new BorderLayout());
|
||||||
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||||
|
contentPanel.setLayout(null);
|
||||||
|
{
|
||||||
|
address = new JTextField();
|
||||||
|
address.setBounds(10, 26, 215, 20);
|
||||||
|
contentPanel.add(address);
|
||||||
|
address.setColumns(10);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
user = new JTextField();
|
||||||
|
user.setBounds(10, 72, 215, 20);
|
||||||
|
contentPanel.add(user);
|
||||||
|
user.setColumns(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
JLabel lblNewLabel = new JLabel("Server Address");
|
||||||
|
lblNewLabel.setBounds(10, 11, 414, 14);
|
||||||
|
contentPanel.add(lblNewLabel);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_1 = new JLabel("Username");
|
||||||
|
lblNewLabel_1.setBounds(10, 57, 414, 14);
|
||||||
|
contentPanel.add(lblNewLabel_1);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_2 = new JLabel("Password");
|
||||||
|
lblNewLabel_2.setBounds(10, 103, 414, 14);
|
||||||
|
contentPanel.add(lblNewLabel_2);
|
||||||
|
|
||||||
|
pw = new JPasswordField();
|
||||||
|
pw.setBounds(10, 118, 215, 20);
|
||||||
|
contentPanel.add(pw);
|
||||||
|
{
|
||||||
|
JPanel buttonPane = new JPanel();
|
||||||
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||||
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||||
|
{
|
||||||
|
JButton okButton = new JButton("OK");
|
||||||
|
okButton.setActionCommand("OK");
|
||||||
|
okButton.addActionListener(this);
|
||||||
|
buttonPane.add(okButton);
|
||||||
|
getRootPane().setDefaultButton(okButton);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JButton cancelButton = new JButton("Cancel");
|
||||||
|
cancelButton.setActionCommand("Cancel");
|
||||||
|
cancelButton.addActionListener(this);
|
||||||
|
buttonPane.add(cancelButton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (e.getActionCommand().equals("OK")) {
|
||||||
|
app.start(address.getText(), 110, user.getText(), new String(pw.getPassword()));
|
||||||
|
} else if (e.getActionCommand().equals("Cancel")) {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
110
MyMail.java
110
MyMail.java
@@ -1,18 +1,17 @@
|
|||||||
import java.util.Iterator;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
public class MyMail {
|
public class MyMail {
|
||||||
|
|
||||||
public static final String POP3_SERVER = "127.0.0.1";
|
// public static final String POP3_SERVER = "pop3.neugebauer.cc";
|
||||||
|
//
|
||||||
public static final int POP3_PORT = 110;
|
// public static final int POP3_PORT = 110;
|
||||||
|
//
|
||||||
public static final String POP3_USER = "user1";
|
// public static final String POP3_USER = "informatik@neugebauer.cc";
|
||||||
|
//
|
||||||
public static final String POP3_PASS = "user1";
|
// public static final String POP3_PASS = "ifq2_user1";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// new MyMail();
|
new MyMail();
|
||||||
new MyMail("pop3.neugebauer.cc", 110, "informatik@neugebauer.cc", "ifq2_user1");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String ip;
|
private String ip;
|
||||||
@@ -29,23 +28,34 @@ public class MyMail {
|
|||||||
|
|
||||||
private String lastError;
|
private String lastError;
|
||||||
|
|
||||||
|
private LoginGUI login;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verbindet zu einem lokalen POP3-Server.
|
* Verbindet zu einem lokalen POP3-Server.
|
||||||
*/
|
*/
|
||||||
public MyMail() {
|
public MyMail() {
|
||||||
this(POP3_SERVER, POP3_PORT, POP3_USER, POP3_PASS);
|
login = new LoginGUI(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyMail(String pIP, String pUser, String pPassword) {
|
public void start(String pIP, int pPort, String pUser, String pPassword) {
|
||||||
this(pIP, 110, pUser, pPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MyMail(String pIP, int pPort, String pUser, String pPassword) {
|
|
||||||
ip = pIP;
|
ip = pIP;
|
||||||
port = pPort;
|
port = pPort;
|
||||||
user = pUser;
|
user = pUser;
|
||||||
password = pPassword;
|
password = pPassword;
|
||||||
|
|
||||||
|
if (!connectToServer()) {
|
||||||
|
JOptionPane.showMessageDialog(null, lastError, "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!login()) {
|
||||||
|
JOptionPane.showMessageDialog(null, lastError, "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
con.send("QUIT");
|
||||||
|
con.close();
|
||||||
|
login.dispose();
|
||||||
|
|
||||||
// GUI erstellen und Status setzen.
|
// GUI erstellen und Status setzen.
|
||||||
gui = new MyMailGUI(this);
|
gui = new MyMailGUI(this);
|
||||||
gui.setStatus("App gestartet");
|
gui.setStatus("App gestartet");
|
||||||
@@ -112,14 +122,14 @@ public class MyMail {
|
|||||||
con.send("USER " + user);
|
con.send("USER " + user);
|
||||||
mes = con.receive();
|
mes = con.receive();
|
||||||
if (mes == null || mes.startsWith("-ERR")) {
|
if (mes == null || mes.startsWith("-ERR")) {
|
||||||
lastError = "Ungueltiger Benutzername!";
|
lastError = "Ungültiger Benutzername!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// PASS Kommando senden und Antwort prüfen
|
// PASS Kommando senden und Antwort prüfen
|
||||||
con.send("PASS " + password);
|
con.send("PASS " + password);
|
||||||
mes = con.receive();
|
mes = con.receive();
|
||||||
if (mes == null || mes.startsWith("-ERR")) {
|
if (mes == null || mes.startsWith("-ERR")) {
|
||||||
lastError = "Ungueltiges Passwort!";
|
lastError = "Ungültiges Passwort!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Anmeldung war erfolgreich
|
// Anmeldung war erfolgreich
|
||||||
@@ -169,7 +179,7 @@ public class MyMail {
|
|||||||
boolean connected = connectToServer();
|
boolean connected = connectToServer();
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
// Letzten Fehler anzeigen (wird in connectToServer gesetzt).
|
// Letzten Fehler anzeigen (wird in connectToServer gesetzt).
|
||||||
gui.setError(lastError);
|
lastError = "Fehler beim Verbinden.";
|
||||||
return; // Abbrechen
|
return; // Abbrechen
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +188,7 @@ public class MyMail {
|
|||||||
boolean loggedIn = login();
|
boolean loggedIn = login();
|
||||||
if (!loggedIn) {
|
if (!loggedIn) {
|
||||||
// Letzten Fehler anzeigen (wird in connectToServer gesetzt).
|
// Letzten Fehler anzeigen (wird in connectToServer gesetzt).
|
||||||
gui.setError(lastError);
|
lastError = "Fehler beim Einloggen.";
|
||||||
return; // Abbrechen
|
return; // Abbrechen
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,32 +261,29 @@ public class MyMail {
|
|||||||
// machen.
|
// machen.
|
||||||
// Tipp: Merk dir in einem boolean, ob du im Textkörper oder im Header bist.
|
// Tipp: Merk dir in einem boolean, ob du im Textkörper oder im Header bist.
|
||||||
mes = con.receive();
|
mes = con.receive();
|
||||||
if (header) {
|
if (header) { // Header werden gesucht
|
||||||
if (mes.equals("")) {
|
if (mes.equals("")) { // Header ist nach leerer Zeile zuende
|
||||||
header = false;
|
header = false;
|
||||||
} else if (mes.startsWith("Delivery-date")) {
|
} else if (mes.startsWith("Delivery-date")) {
|
||||||
date = mes.substring(15);
|
date = mes.substring(15);
|
||||||
} else if (mes.startsWith("From")) {
|
} else if (mes.startsWith("From")) {
|
||||||
boolean open = false;
|
sender = mes.substring(mes.indexOf('<') + 1, mes.indexOf('>'));
|
||||||
for (char c : mes.toCharArray()) {
|
|
||||||
if (open) {
|
|
||||||
if (c == '>')
|
|
||||||
break;
|
|
||||||
sender += c;
|
|
||||||
} else if (c == '<') {
|
|
||||||
open = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (mes.startsWith("Subject")) {
|
} else if (mes.startsWith("Subject")) {
|
||||||
subject = mes.substring(9);
|
subject = mes.substring(9);
|
||||||
}
|
}
|
||||||
} else {
|
} else { // Nachricht wird gelesen
|
||||||
mes = mes.replaceAll("=C3=BC", "ü");
|
if (mes.equals(".")) { // ende
|
||||||
mes = mes.replaceAll("=C3=A4", "ä");
|
break;
|
||||||
mes = mes.replaceAll("=C3=B6", "ö");
|
} else if (mes.startsWith("--")) { // weirde header MITTEN DRIN EINFACH SO
|
||||||
mes = mes.replaceAll("=C3=9F", "ß");
|
header = true;
|
||||||
|
} else { // Text der später ausgegeben wird
|
||||||
|
mes = mes.replaceAll("=C3=BC", "ü"); // Umlaute werden ersetzt
|
||||||
|
mes = mes.replaceAll("=C3=A4", "ä");
|
||||||
|
mes = mes.replaceAll("=C3=B6", "ö");
|
||||||
|
mes = mes.replaceAll("=C3=9F", "ß");
|
||||||
text += mes + "\n";
|
text += mes + "\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} // end of while
|
} // end of while
|
||||||
|
|
||||||
return new Mail(pNumber, date, sender, subject, text);
|
return new Mail(pNumber, date, sender, subject, text);
|
||||||
@@ -295,23 +302,46 @@ public class MyMail {
|
|||||||
* gelöscht. Es wird nicht garantiert, dass dies auch dieselbe Mail ist.
|
* gelöscht. Es wird nicht garantiert, dass dies auch dieselbe Mail ist.
|
||||||
*
|
*
|
||||||
* @param pMail Das Mailobjekt, das gelöscht werden soll.
|
* @param pMail Das Mailobjekt, das gelöscht werden soll.
|
||||||
* @todo Vor Löschen prüfen, ob die Mail auf dem Server dieselbe wie pMail
|
* @todo Vor Löschen prüfen, ob die Mail auf dem Server dieselbe wie pMail ist.
|
||||||
* ist.
|
|
||||||
*/
|
*/
|
||||||
public void deleteMail(Mail pMail) {
|
public void deleteMail(Mail pMail) {
|
||||||
// Verbindung erstellen und prüfen
|
// Verbindung erstellen und prüfen
|
||||||
|
boolean connected = connectToServer();
|
||||||
|
if (!connected) {
|
||||||
|
// Letzten Fehler anzeigen (wird in connectToServer gesetzt).
|
||||||
|
gui.setStatus("Fehler beim Verbinden.");
|
||||||
|
return; // Abbrechen
|
||||||
|
}
|
||||||
|
|
||||||
// Anmeldung durchführen und prüfen
|
// Anmeldung durchführen und prüfen
|
||||||
|
boolean loggedIn = login();
|
||||||
|
if (!loggedIn) {
|
||||||
|
// Letzten Fehler anzeigen (wird in connectToServer gesetzt).
|
||||||
|
gui.setStatus("Fehler beim Einloggen.");
|
||||||
|
return; // Abbrechen
|
||||||
|
}
|
||||||
|
|
||||||
// Prüfen, ob eine Mail mit der Nummer vorhanden ist
|
// Prüfen, ob eine Mail mit der Nummer vorhanden ist
|
||||||
// Hinweis: Die Nummer der Mail ist über pMail.getNumber() abrufbar
|
// Hinweis: Die Nummer der Mail ist über pMail.getNumber() abrufbar
|
||||||
|
Mail m = getMail(pMail.getNumber());
|
||||||
|
if (m == null) {
|
||||||
|
gui.setStatus("Die mail konnte nicht gelöscht werden, da sie nicht existiert.");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
// Mail als gelöscht markieren
|
// Mail als gelöscht markieren
|
||||||
|
//**** con.send("dele " + pMail.getNumber());
|
||||||
// Löschung ausführen und Verbindung beenden.
|
// Löschung ausführen und Verbindung beenden.
|
||||||
|
con.send("quit");
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.setStatus("Mail erfolgreich gelöscht.");
|
||||||
|
|
||||||
// Mail aus der GUI entfernen und neu aufbauen.s
|
// Mail aus der GUI entfernen und neu aufbauen.s
|
||||||
gui.removeMailFromList(pMail);
|
gui.removeMailFromList(pMail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void switchUser() {
|
||||||
|
login = new LoginGUI(this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class MyMailGUI extends JFrame implements ActionListener, ListSelectionLi
|
|||||||
|
|
||||||
private JLabel jlStatusText;
|
private JLabel jlStatusText;
|
||||||
|
|
||||||
private JButton jbReload, jbDelete, jbNew, jbReply, jbSettings;
|
private JButton jbReload, jbDelete, jbNew, jbReply, jbSettings, jbSwitchUser;
|
||||||
|
|
||||||
private JTable jtMaillist;
|
private JTable jtMaillist;
|
||||||
|
|
||||||
@@ -99,7 +99,10 @@ public class MyMailGUI extends JFrame implements ActionListener, ListSelectionLi
|
|||||||
if( e.getActionCommand().equals("load") ) {
|
if( e.getActionCommand().equals("load") ) {
|
||||||
app.getAllMails();
|
app.getAllMails();
|
||||||
} else if( e.getActionCommand().equals("delete") ) {
|
} else if( e.getActionCommand().equals("delete") ) {
|
||||||
//app.deleteMail(jtMaillist.getSelectedRow()+1);
|
app.deleteMail(mails.get(jtMaillist.getSelectedRow()));
|
||||||
|
} else if (e.getActionCommand().equals("switchUser")) {
|
||||||
|
app.switchUser();
|
||||||
|
dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +148,11 @@ public class MyMailGUI extends JFrame implements ActionListener, ListSelectionLi
|
|||||||
jbDelete.setIcon(loadImageIcon("email_delete.png"));
|
jbDelete.setIcon(loadImageIcon("email_delete.png"));
|
||||||
jpSidebar.add(jbDelete);
|
jpSidebar.add(jbDelete);
|
||||||
|
|
||||||
|
jbSwitchUser = new JButton("Abmelden");
|
||||||
|
jbSwitchUser.setActionCommand("switchUser");
|
||||||
|
jbSwitchUser.addActionListener(this);
|
||||||
|
jpSidebar.add(jbSwitchUser);
|
||||||
|
|
||||||
jbSettings = new JButton("Einstellungen");
|
jbSettings = new JButton("Einstellungen");
|
||||||
jbSettings.setActionCommand("settings");
|
jbSettings.setActionCommand("settings");
|
||||||
jbSettings.addActionListener(this);
|
jbSettings.addActionListener(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user