forked from IF-LK-2020/mymail
Compare commits
3 Commits
7f83467a07
...
c035137020
Author | SHA1 | Date |
---|---|---|
Asecave | c035137020 | |
Asecave | ddf81f11aa | |
Asecave | 587beb098c |
|
@ -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());
|
||||
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()));
|
||||
dispose();
|
||||
} else if (e.getActionCommand().equals("Cancel")) {
|
||||
System.out.println("Cancel");
|
||||
}
|
||||
}
|
||||
}
|
96
MyMail.java
96
MyMail.java
|
@ -1,18 +1,16 @@
|
|||
import java.util.Iterator;
|
||||
|
||||
public class MyMail {
|
||||
|
||||
public static final String POP3_SERVER = "127.0.0.1";
|
||||
|
||||
public static final int POP3_PORT = 110;
|
||||
|
||||
public static final String POP3_USER = "user1";
|
||||
|
||||
public static final String POP3_PASS = "user1";
|
||||
// public static final String POP3_SERVER = "pop3.neugebauer.cc";
|
||||
//
|
||||
// public static final int POP3_PORT = 110;
|
||||
//
|
||||
// public static final String POP3_USER = "informatik@neugebauer.cc";
|
||||
//
|
||||
// public static final String POP3_PASS = "ifq2_user1";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// new MyMail();
|
||||
new MyMail("pop3.neugebauer.cc", 110, "informatik@neugebauer.cc", "ifq2_user1");
|
||||
new MyMail();
|
||||
}
|
||||
|
||||
private String ip;
|
||||
|
@ -28,19 +26,17 @@ public class MyMail {
|
|||
private String password;
|
||||
|
||||
private String lastError;
|
||||
|
||||
private LoginGUI loginGUI;
|
||||
|
||||
/**
|
||||
* Verbindet zu einem lokalen POP3-Server.
|
||||
*/
|
||||
public MyMail() {
|
||||
this(POP3_SERVER, POP3_PORT, POP3_USER, POP3_PASS);
|
||||
loginGUI = new LoginGUI(this);
|
||||
}
|
||||
|
||||
public MyMail(String pIP, String pUser, String pPassword) {
|
||||
this(pIP, 110, pUser, pPassword);
|
||||
}
|
||||
|
||||
public MyMail(String pIP, int pPort, String pUser, String pPassword) {
|
||||
public void start(String pIP, int pPort, String pUser, String pPassword) {
|
||||
ip = pIP;
|
||||
port = pPort;
|
||||
user = pUser;
|
||||
|
@ -169,7 +165,7 @@ public class MyMail {
|
|||
boolean connected = connectToServer();
|
||||
if (!connected) {
|
||||
// Letzten Fehler anzeigen (wird in connectToServer gesetzt).
|
||||
gui.setError(lastError);
|
||||
lastError = "Fehler beim Verbinden.";
|
||||
return; // Abbrechen
|
||||
}
|
||||
|
||||
|
@ -178,7 +174,7 @@ public class MyMail {
|
|||
boolean loggedIn = login();
|
||||
if (!loggedIn) {
|
||||
// Letzten Fehler anzeigen (wird in connectToServer gesetzt).
|
||||
gui.setError(lastError);
|
||||
lastError = "Fehler beim Einloggen.";
|
||||
return; // Abbrechen
|
||||
}
|
||||
|
||||
|
@ -251,31 +247,28 @@ public class MyMail {
|
|||
// machen.
|
||||
// Tipp: Merk dir in einem boolean, ob du im Textkörper oder im Header bist.
|
||||
mes = con.receive();
|
||||
if (header) {
|
||||
if (mes.equals("")) {
|
||||
if (header) { // Header werden gesucht
|
||||
if (mes.equals("")) { // Header ist nach leerer Zeile zuende
|
||||
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;
|
||||
}
|
||||
}
|
||||
sender = mes.substring(mes.indexOf('<') + 1, mes.indexOf('>'));
|
||||
} 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";
|
||||
} else { // Nachricht wird gelesen
|
||||
if (mes.equals(".")) { // ende
|
||||
break;
|
||||
} else if (mes.startsWith("--")) { // weirde header MITTEN DRIN EINFACH SO
|
||||
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";
|
||||
}
|
||||
}
|
||||
} // end of while
|
||||
|
||||
|
@ -295,20 +288,39 @@ public class MyMail {
|
|||
* gelöscht. Es wird nicht garantiert, dass dies auch dieselbe Mail ist.
|
||||
*
|
||||
* @param pMail Das Mailobjekt, das gelöscht werden soll.
|
||||
* @todo Vor Löschen prüfen, ob die Mail auf dem Server dieselbe wie pMail
|
||||
* ist.
|
||||
* @todo Vor Löschen prüfen, ob die Mail auf dem Server dieselbe wie pMail ist.
|
||||
*/
|
||||
public void deleteMail(Mail pMail) {
|
||||
// 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
|
||||
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
|
||||
// Hinweis: Die Nummer der Mail ist über pMail.getNumber() abrufbar
|
||||
|
||||
// Mail als gelöscht markieren
|
||||
|
||||
// Löschung ausführen und Verbindung beenden.
|
||||
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
|
||||
//**** con.send("dele " + pMail.getNumber());
|
||||
// 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
|
||||
gui.removeMailFromList(pMail);
|
||||
|
|
|
@ -99,7 +99,7 @@ public class MyMailGUI extends JFrame implements ActionListener, ListSelectionLi
|
|||
if( e.getActionCommand().equals("load") ) {
|
||||
app.getAllMails();
|
||||
} else if( e.getActionCommand().equals("delete") ) {
|
||||
//app.deleteMail(jtMaillist.getSelectedRow()+1);
|
||||
app.deleteMail(mails.get(jtMaillist.getSelectedRow()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue