From 182437dc00cb76df47fa55fabab99cf9c8b2ccee Mon Sep 17 00:00:00 2001 From: Matthias Guenther Date: Sat, 22 Oct 2011 11:44:15 +0200 Subject: [PATCH] add main files of the project --- GUIKontoInformation.java | 181 +++++++++ GUIMailsend.java | 256 ++++++++++++ GUIMailsget.java | 358 +++++++++++++++++ GUIMain.java | 444 +++++++++++++++++++++ GUITreeInsert.java | 239 +++++++++++ Inbox MG/Fri Aug 14 18_52_59 CEST 2009.txt | 4 + Inbox MG/Fri Dec 26 10_42_10 CET 2008.txt | 4 + Inbox MG/Mon Aug 29 17_15_19 CEST 2005.txt | 4 + Inbox MG/Mon Jun 08 17_22_41 CEST 2009.txt | 4 + Inbox MG/Sat Feb 28 10_41_20 CET 2009.txt | 4 + Inbox MG/Sat Feb 28 10_46_22 CET 2009.txt | 4 + Inbox MG/Sun Aug 16 10_52_05 CEST 2009.txt | 4 + Inbox MG/Sun May 17 12_45_40 CEST 2009.txt | 4 + Inbox MG/Thu Jan 01 11_37_47 CET 2009.txt | 4 + Inbox MG/Tue Jul 21 18_42_56 CEST 2009.txt | 4 + Inbox MG/Wed May 06 13_16_24 CEST 2009.txt | 4 + Inbox MG/Wed May 06 13_39_53 CEST 2009.txt | 4 + MG kontoinfos.kondat | 1 + MailApi.java | 120 ++++++ README.md | 4 +- 20 files changed, 1649 insertions(+), 2 deletions(-) create mode 100755 GUIKontoInformation.java create mode 100755 GUIMailsend.java create mode 100755 GUIMailsget.java create mode 100755 GUIMain.java create mode 100755 GUITreeInsert.java create mode 100755 Inbox MG/Fri Aug 14 18_52_59 CEST 2009.txt create mode 100755 Inbox MG/Fri Dec 26 10_42_10 CET 2008.txt create mode 100755 Inbox MG/Mon Aug 29 17_15_19 CEST 2005.txt create mode 100755 Inbox MG/Mon Jun 08 17_22_41 CEST 2009.txt create mode 100755 Inbox MG/Sat Feb 28 10_41_20 CET 2009.txt create mode 100755 Inbox MG/Sat Feb 28 10_46_22 CET 2009.txt create mode 100755 Inbox MG/Sun Aug 16 10_52_05 CEST 2009.txt create mode 100755 Inbox MG/Sun May 17 12_45_40 CEST 2009.txt create mode 100755 Inbox MG/Thu Jan 01 11_37_47 CET 2009.txt create mode 100755 Inbox MG/Tue Jul 21 18_42_56 CEST 2009.txt create mode 100755 Inbox MG/Wed May 06 13_16_24 CEST 2009.txt create mode 100755 Inbox MG/Wed May 06 13_39_53 CEST 2009.txt create mode 100755 MG kontoinfos.kondat create mode 100755 MailApi.java diff --git a/GUIKontoInformation.java b/GUIKontoInformation.java new file mode 100755 index 0000000..1960905 --- /dev/null +++ b/GUIKontoInformation.java @@ -0,0 +1,181 @@ + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +import javax.swing.*; +import java.io.*; + +/* + * Version 2.0 + * Matthias Guenther + * speichert Infos ueber die Benutzer ab + */ +public class GUIKontoInformation extends GUIMain implements ActionListener { + + private JPanel complete, emailadress, username, uservalidationname, + userpass, postentrance, postexit, check; + public JTextField portin, postex; + public JTextField emailadressinput = new JTextField(25); + public JTextField usernameinput = new JTextField(25); + public JTextField uservalidationnameinput = new JTextField(25); + public JTextField userpassinput = new JTextField(25); + public JTextField postentranceinput = new JTextField(25); + public JTextField postexitinput = new JTextField(25); + private JCheckBox save; + private JButton ok, abort; + private JFrame kontoInformationFame; + public String informations; + private boolean saveInformation = false; + + // constructor to get login-information + public void GUIKontoInformationCreate() { + + // create the main frame + kontoInformationFame = new JFrame("Email-Client"); + + // to exit the frame when the x is pressed + kontoInformationFame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + kontoInformationFame.setSize(500, 450); + emailadress = new JPanel(new FlowLayout(FlowLayout.LEFT)); + emailadress.add(new JLabel("email Adresse")); + emailadress.add(emailadressinput); + + username = new JPanel(new FlowLayout(FlowLayout.LEFT)); + username.add(new JLabel("Name:")); + username.add(usernameinput); + + uservalidationname = new JPanel(new FlowLayout(FlowLayout.LEFT)); + uservalidationname.add(new JLabel("Benutzererkennung:")); + uservalidationname.add(uservalidationnameinput); + + userpass = new JPanel(new FlowLayout(FlowLayout.LEFT)); + save = new JCheckBox("Passwort speichern"); + save.addItemListener(new CheckBoxListener()); + + userpass.add(new JLabel("Passwort:")); + userpass.add(userpassinput); + userpass.add(save); + + postentrance = new JPanel(new FlowLayout(FlowLayout.LEFT)); + portin = new JTextField(6); + portin.setText("110"); + postentrance.add(new JLabel("Posteingang:")); + postentrance.add(postentranceinput); + postentrance.add(new JLabel("Port:")); + postentrance.add(portin); + + postexit = new JPanel(new FlowLayout(FlowLayout.LEFT)); + postexit.add(new JLabel("Postausgang:")); + postex = new JTextField(6); + postex.setText("10"); + postexit.add(postexitinput); + postexit.add(new JLabel("Port:")); + postexit.add(postex); + + // create the buttons for ok and abort + check = new JPanel(new FlowLayout(FlowLayout.CENTER)); + ok = new JButton("Ok"); + ok.addActionListener(this); + abort = new JButton("Abbrechen"); + abort.addActionListener(this); + check.add(ok); + check.add(abort); + + // create a great panel complete which contain all other panels + complete = new JPanel(new GridLayout(8, 1)); + complete.add(new JLabel("Benutzerdaten eingeben: ")); + complete.add(emailadress); + complete.add(username); + complete.add(uservalidationname); + complete.add(userpass); + complete.add(postentrance); + complete.add(postexit); + complete.add(check); + + // add the great panel complete to the frame + kontoInformationFame.add(complete); + kontoInformationFame.setVisible(true); + + } + + public void actionPerformed(ActionEvent e) { + Object obj = e.getSource(); + + if (obj == ok) { + if (saveInformation == true) { + saveUserInfo(); + writeUserInfo(); + kontoInformationFame.setVisible(false); + } else { + writeUserInfo(); + kontoInformationFame.setVisible(false); + } + + } + + if (obj == abort) { + kontoInformationFame.setVisible(false); + } + + } + + // action listener if the Account Infos should be saved permanetly + class CheckBoxListener implements ItemListener { + + public void itemStateChanged(ItemEvent evt) { + saveInformation = save.isSelected(); + } + } + + // write the user infos in the global array + public void writeUserInfo() { + String emailadressin = emailadressinput.getText(); + String usernamein = usernameinput.getText(); + String uservalidationnamein = uservalidationnameinput.getText(); + String userpassin = userpassinput.getText(); + String postentrancein = postentranceinput.getText(); + String postinprt = portin.getText(); + String postexitin = postexitinput.getText(); + String postexitprt = postex.getText(); + + + informations = emailadressin + "#######" + usernamein + "#######" + uservalidationnamein + "#######" + userpassin + "#######" + postentrancein + "#######" + postinprt + "#######" + postexitin + "#######" + postexitprt; + + + userInfos = informations.split("#######"); + } + + public void saveUserInfo() { + File userName = new File(userInfos[1]); + userName.mkdir(); + String emailadressin = emailadressinput.getText(); + String usernamein = usernameinput.getText(); + String uservalidationnamein = uservalidationnameinput.getText(); + String userpassin = userpassinput.getText(); + String postentrancein = postentranceinput.getText(); + String postinprt = portin.getText(); + String postexitin = postexitinput.getText(); + String postexitprt = postex.getText(); + + String tmp = ""; + tmp = emailadressin + "#######" + usernamein + "#######" + uservalidationnamein + "#######" + userpassin + "#######" + postentrancein + "#######" + postinprt + "#######" + postexitin + "#######" + postexitprt; + + try { + FileWriter fw = new FileWriter(usernameinput.getText() + " kontoinfos.kondat"); + fw.write(tmp); + fw.close(); + } catch (IOException msg) { + System.err.println("Cannot create file"); + } + + } + + public static void main(String[] args) { + GUIKontoInformation test = new GUIKontoInformation(); + test.GUIKontoInformationCreate(); + } +} diff --git a/GUIMailsend.java b/GUIMailsend.java new file mode 100755 index 0000000..64676b0 --- /dev/null +++ b/GUIMailsend.java @@ -0,0 +1,256 @@ + +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.TextArea; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; +import javax.activation.DataHandler; +import javax.activation.DataSource; +import javax.activation.FileDataSource; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.mail.*; +import javax.mail.internet.*; + +/* + * Version 2.0 + * Matthias Guenther + * um Mails zu versenden inklusive Anhaenge + */ +public class GUIMailsend extends GUIMain { + + private JPanel from, to, cc, subject, text, allinone, check; + public JTextField frominput, toinput, ccinput, subjectinput; + private TextArea messagebodyinput; + private JButton send, delete, quit, attach; + public JFrame mailSendFrame; + // um mehrere Empf�nger reinzuschreiben + private InternetAddress too[]; + // diese Informationen muss aus dem userInfos[] array gewonnen werden + // userInfos[2] + //private String username = "razinger"; + private String username = userInfos[2]; + // userInfos[3] + //private String userpass = "Ratzinger"; + private String userpass = userInfos[3]; + // userInfos[6] + //private String smtpServer = "smtp.web.de"; + private String smtpServer = userInfos[6]; + private String attachFile; + public String fromString = "razinger@web.de"; + public String subjectString = "Test"; + public String toString = "lordmatze@googlemail.com"; + public String contentString = ""; + private boolean attachbool = false; + + public void guiMailsend() { + // create the frame + mailSendFrame = new JFrame("Message"); + mailSendFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + mailSendFrame.setSize(500, 600); + + from = new JPanel(new FlowLayout(FlowLayout.LEFT)); + frominput = new JTextField(25); + frominput.setText(fromString); + from.add(new JLabel("From:")); + from.add(frominput); + + to = new JPanel(new FlowLayout(FlowLayout.LEFT)); + toinput = new JTextField(25); + toinput.setText(toString); + to.add(new JLabel("To:")); + to.add(toinput); + + cc = new JPanel(new FlowLayout(FlowLayout.LEFT)); + ccinput = new JTextField(25); + cc.add(new JLabel("CC:")); + cc.add(ccinput); + + subject = new JPanel(new FlowLayout(FlowLayout.LEFT)); + subjectinput = new JTextField(25); + subjectinput.setText(subjectString); + subject.add(new JLabel("Subject:")); + subject.add(subjectinput); + + text = new JPanel(new FlowLayout(FlowLayout.LEFT)); + text.add(new JLabel("Message:")); + + messagebodyinput = new TextArea(); + messagebodyinput.setText(contentString); + + send = new JButton("Send"); + send.addActionListener(new ButtonSendListener()); + + quit = new JButton("Quit"); + quit.addActionListener(new ButtonQuitListener()); + + delete = new JButton("Delete"); + delete.addActionListener(new ButtonDeleteListener()); + + attach = new JButton("Attach"); + attach.addActionListener(new ButtonAttachListener()); + // the buttons + check = new JPanel(new FlowLayout(FlowLayout.CENTER)); + check.add(send); + check.add(quit); + check.add(delete); + check.add(attach); + + allinone = new JPanel(new GridLayout(7, 1)); + allinone.add(from); + allinone.add(to); + allinone.add(cc); + allinone.add(subject); + allinone.add(text); + allinone.add(messagebodyinput); + allinone.add(check); + + mailSendFrame.add(allinone); + mailSendFrame.setVisible(true); + } + + // add the fucking listeners + class ButtonSendListener implements ActionListener { + + public void actionPerformed(ActionEvent evt) { + sendMail(); + mailSendFrame.setVisible(false); + } + } + + class ButtonQuitListener implements ActionListener { + + public void actionPerformed(ActionEvent evt) { + mailSendFrame.setVisible(false); + } + } + + class ButtonDeleteListener implements ActionListener { + + public void actionPerformed(ActionEvent evt) { + frominput.setText(""); + toinput.setText(""); + ccinput.setText(""); + subjectinput.setText(""); + messagebodyinput.setText(""); + } + } + + class ButtonAttachListener implements ActionListener { + + public void actionPerformed(ActionEvent evt) { + JFileChooser dialog = new JFileChooser(); + int tmp = dialog.showOpenDialog(dialog); + getFilePath(dialog.getSelectedFile()); + + } + } + + public void sendMail() { + + MailAuthenticator auth = new MailAuthenticator(username, userpass); + + Properties properties = new Properties(); + + // add the serveradress to properties + properties.put("mail.smtp.host", smtpServer); + + properties.setProperty("mail.smtp.port", "587"); + + // smtp needs authentication so it muss be true + properties.put("mail.smtp.auth", "true"); + + Session session = Session.getDefaultInstance(properties, auth); + + try { + String bla = toinput.getText(); + + // this simple loop enable multiple recipients + String[] tmp = new String[bla.split(",").length]; + tmp = bla.split(","); + Message msg = new MimeMessage(session); + too = new InternetAddress[tmp.length]; + for (int i = 0; i < tmp.length; i++) { + too[i] = new InternetAddress(tmp[i]); + } + + // set sender adress and recipients + msg.setFrom(new InternetAddress(frominput.getText())); + msg.setRecipients(Message.RecipientType.TO, too); + + if (attachbool == true) { + Multipart multipart = new MimeMultipart(); + BodyPart messageBodyPart = new MimeBodyPart(); + File fileattach = new File(attachFile); + System.out.println(attachFile); + // create an object for the attach + DataSource attach = new FileDataSource(fileattach); + messageBodyPart.setDataHandler(new DataHandler(attach)); + + // to give the attachement a name + messageBodyPart.setFileName(attachFile); + multipart.addBodyPart(messageBodyPart); + msg.setSubject(subjectinput.getText()); + msg.setText(messagebodyinput.getText()); + msg.setContent(multipart); + Transport.send(msg); + + } else { + msg.setSubject(subjectinput.getText()); + msg.setText(messagebodyinput.getText()); + Transport.send(msg); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + // need to authentificate + class MailAuthenticator extends Authenticator { + + private final String user; + private final String password; + + public MailAuthenticator(String u, String p) { + this.user = u; + this.password = p; + } + + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(this.user, this.password); + } + } + + // method to get the path of the attached file and to open the dialog + public void getFilePath(File datei) { + try { + JInternalFrame FrameChoose = new JInternalFrame(datei.toString(), + true, true, true, true); + JTextArea text = new JTextArea(10, 40); + text.setLineWrap(true); + attachbool = true; + text.read(new FileReader(datei), null); + attachFile = datei.getAbsolutePath(); + System.out.println(attachbool); + + } catch (IOException ex) { + System.out.println("Cant't find file"); + } + } + + public static void main(String[] args) { + GUIMailsend test = new GUIMailsend(); + test.guiMailsend(); + } +} diff --git a/GUIMailsget.java b/GUIMailsget.java new file mode 100755 index 0000000..60a6e6d --- /dev/null +++ b/GUIMailsget.java @@ -0,0 +1,358 @@ + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Container; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.TextArea; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Properties; +import javax.mail.Folder; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.Store; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListCellRenderer; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +/* + * Version 3.0 + * Matthias Guenther + * mails abrufen - dies war ganz schoen schwierig + */ +public class GUIMailsget extends GUIMain implements ActionListener { + + private JList jlist; + private TextArea definitionArea; + private JPanel mailsReceiveComplete, subPanel, fromPanel, toPanel, + messageData, abortPanel; + private JButton abort, rewrite, answer; + private JFrame messageFrame; + private JLabel subLab, subLabOutput, fromLab, fromLabOutput, toLab, + toLabOutput; + // userInfos[2] + private String userId = userInfos[2]; + // userInfos[3] + private String userPass = userInfos[3]; + // userInfos[4] + //private String connectURL = "pop3.web.de"; + private String connectURL = userInfos[4]; + private File userName; + // store the messages + private Message[] message; + private boolean checkEqual = false; + private int num; + private Store store; + Folder folder; + + public void guiMailsget() { + try { + messageFrame = new JFrame("Mail Informations"); + + currentUserDir = dir + "Inbox " + userInfos[1]; + userName = new File(currentUserDir); + + messageFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + Session session = Session.getInstance(new Properties()); + // get a Store object + store = session.getStore("pop3"); + store.connect(connectURL, userId, userPass); + + // get "INBOX" + folder = store.getFolder("INBOX"); + folder.open(Folder.READ_WRITE); + + // this variable counts the message number + int count = folder.getMessageCount(); + + System.out.println(count + " new messages"); + message = folder.getMessages(); + + // set size of the frame for the messages + messageFrame.setSize(600, 400); + mailsReceiveComplete = new JPanel(new BorderLayout()); + mailsReceiveComplete.setSize(300, 100); + + // to mark and save new emails + Object elements[][] = new Object[count][4]; + for (int j = 0; j < elements.length; j++) { + num = j; + try { + searchLocalDir(userName); + System.out.println("aktuell: " + checkEqual); + } catch (IOException e) { + e.printStackTrace(); + } + + for (int z = 0; z <= 3; z++) { + if (z == 0 && checkEqual == true) { + elements[j][z] = new Font("TimesRoman", Font.BOLD, 11); + } else if (z == 0) { + elements[j][z] = new Font("TimesRoman", Font.BOLD, 13); + } else if (z == 1 && checkEqual == true) { + elements[j][z] = Color.gray; + } else if (z == 1) { + elements[j][z] = Color.black; + } else if (z == 2 && checkEqual == true) { + elements[j][z] = new DiamondIcon(Color.gray); + } else if (z == 2) { + elements[j][z] = new DiamondIcon(Color.red); + } else { + + elements[j][z] = message[j].getSubject() + " " + message[j].getFrom()[0] + " " + message[j].getSentDate(); + + } + + } + + checkEqual = false; + + } + + JFrame frame = new JFrame("Mail List"); + Container contentPane = frame.getContentPane(); + + // create a new listwith the whole emails inside, with the specific + // infos + jlist = new JList(elements); + + ListCellRenderer renderer = new ComplexCellRenderer(); + jlist.setCellRenderer(renderer); + jlist.addListSelectionListener(new ListSelectionListener() { + + public void valueChanged(ListSelectionEvent event) { + try { + JList source = (JList) event.getSource(); + int number = source.getSelectedIndex(); + definitionArea.setText(message[number].getContent().toString()); + subLabOutput.setText(message[number].getSubject().toString()); + fromLabOutput.setText(message[number].getFrom()[0].toString()); + toLabOutput.setText(message[number].getAllRecipients()[0].toString()); + + // to write that this message was written + FileWriter fw = null; + + try { + String tmp = message[number].getSentDate().toString(); + String tmpparse = tmp.replaceAll(":", "_"); + fw = new FileWriter(currentUserDir + "/" + tmpparse + ".txt"); + String tmp1 = "True\n[FROM]: " + (message[number].getFrom()[0].toString() + "\n"); + String tmp2 = "[SUBJECT]: " + (message[number].getSubject().toString() + "\n"); + String tmp3 = "[CONTENT]: " + (message[number].getContent().toString()); + String messageContentTmp = tmp1 + tmp2 + tmp3; + fw.write(messageContentTmp); + tmp = ""; + fw.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + + } catch (IOException e) { + e.printStackTrace(); + + } catch (MessagingException e) { + e.printStackTrace(); + } + + } + }); + mailsReceiveComplete.add("North", jlist); + JScrollPane scrollPane = new JScrollPane(jlist); + scrollPane.setSize(100, 300); + contentPane.add(scrollPane, BorderLayout.CENTER); + + frame.setSize(450, 400); + frame.setLocation(600, 0); + frame.setVisible(true); + + userName.mkdir(); + + subPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + subLab = new JLabel("[SUBJECT]:"); + subLabOutput = new JLabel(); + subPanel.add(subLab); + subPanel.add(subLabOutput); + + fromPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + fromLab = new JLabel("[FROM]:"); + fromLabOutput = new JLabel(); + fromPanel.add(fromLab); + fromPanel.add(fromLabOutput); + + toPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + toLab = new JLabel("[To]:"); + toLabOutput = new JLabel(); + toPanel.add(toLab); + toPanel.add(toLabOutput); + + abortPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); + abort = new JButton("Quit"); + abort.addActionListener(this); + rewrite = new JButton("Reanswer"); + rewrite.addActionListener(this); + answer = new JButton("Answer"); + answer.addActionListener(this); + + abortPanel.add(answer); + abortPanel.add(rewrite); + abortPanel.add(abort); + + messageData = new JPanel(); + messageData.setLayout(new GridLayout(5, 1)); + messageData.add(subPanel); + messageData.add(fromPanel); + messageData.add(toPanel); + + // mergin all Message Data from abovethe components together + definitionArea = new TextArea(); + definitionArea.setEditable(false); + + mailsReceiveComplete.add("Center", messageData); + mailsReceiveComplete.add("South", definitionArea); + mailsReceiveComplete.add("East", abortPanel); + messageFrame.add(mailsReceiveComplete); + messageFrame.setVisible(true); + } catch (MessagingException msg) { + System.out.println(msg); + } + + } + + // search for mails on the account + public void searchLocalDir(File dir) throws IOException { + File[] files = dir.listFiles(); + if (files != null) { + for (int i = 0; i < files.length; i++) { + try { + // to parse the Strings + String checktmp = message[num].getSentDate() + ".txt"; + String check = checktmp.replaceAll(":", "_"); + if (check.equals(files[i].getName())) { + + // check if the file starts with True + String strLine = ""; + try { + // open file to read it + BufferedReader oRead = new BufferedReader( + new FileReader(currentUserDir + "/" + files[i].getName())); + while (null != (strLine = oRead.readLine())) { + if (strLine.startsWith("True")) { + checkEqual = true; + } + } + oRead.close(); + } catch (FileNotFoundException exFileNotFound) { + System.out.println(exFileNotFound); + } catch (IOException exIO) { + System.out.println(exIO); + } catch (Exception eAllg) { + System.out.println(eAllg); + } + + } + } catch (MessagingException e) { + e.printStackTrace(); + } + + } + } + } + + // for the buttons to ander + public void actionPerformed(ActionEvent e) { + Object obj = e.getSource(); + if (obj == abort) { + messageFrame.setVisible(false); + try { + folder.close(false); + store.close(); + } catch (MessagingException e1) { + e1.printStackTrace(); + } + } + if (obj == rewrite) { + int index = jlist.getSelectedIndex(); + + try { + // get the contents of the selected message + fromLabOutput.setText(message[index].getFrom()[0].toString()); + subLabOutput.setText(message[index].getSubject().toString()); + definitionArea.setText(message[index].getContent().toString()); + + // get the strings of these tmp infos of the messages + String tmp1 = fromLabOutput.getText(); + String tmp2 = subLabOutput.getText(); + String tmp3 = definitionArea.getText(); + + GUIMailsend send = new GUIMailsend(); + + // setting the parameter + send.fromString = tmp1; + send.subjectString = tmp2; + send.contentString = tmp3; + send.toString = ""; + send.guiMailsend(); + } catch (IOException e1) { + } catch (MessagingException e1) { + } + } + + // the same as above + if (obj == answer) { + int index = jlist.getSelectedIndex(); + try { + fromLabOutput.setText(message[index].getFrom()[0].toString()); + subLabOutput.setText(message[index].getSubject().toString()); + definitionArea.setText(message[index].getContent().toString()); + + // get the strings of these tmp infos of the messages + String tmp1 = fromLabOutput.getText(); + String tmp2 = subLabOutput.getText(); + String tmp3 = definitionArea.getText(); + String tmp4 = message[index].getSentDate().toString(); + + // create a new object + GUIMailsend send = new GUIMailsend(); + + String[] ak = tmp3.split("\n"); + String content = ""; + String tmpp; + for (int i = 0; i < ak.length; i++) { + tmpp = "> " + ak[i]; + content = content + tmpp + "\n"; + } + String infos = tmp1 + " wrote " + tmp4 + "\n" + content; + send.fromString = tmp1; + send.subjectString = "RE: " + tmp2; + send.contentString = infos; + send.guiMailsend(); + } catch (Exception msg) { + System.out.println(msg); + } + + } + + } + + public static void main(String[] args) { + + GUIMailsget test = new GUIMailsget(); + test.guiMailsget(); + } +} diff --git a/GUIMain.java b/GUIMain.java new file mode 100755 index 0000000..31e44fc --- /dev/null +++ b/GUIMain.java @@ -0,0 +1,444 @@ + +import java.awt.BorderLayout; +import java.awt.CheckboxMenuItem; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.GridLayout; +import java.awt.List; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.Panel; +import java.awt.Polygon; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import javax.swing.DefaultListCellRenderer; +import javax.swing.Icon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.ListCellRenderer; + +/* + * Version 2.0 + * Matthias Guenther + * Hauptprogramm - simply the best + */ +public class GUIMain { + + public TextArea myTextArea; + public TextField absender, empfaenger, empfaengerCC, subject; + public Panel buttonPanel; + public Menu file, accounts, kontenMenu, info; + public MenuItem saveItem, exit, accountnew, accountedit, readmail, + writemail, accountavailable, managelocalfiles; + public CheckboxMenuItem autoSave; + public JLabel edit; + public MenuBar menucomplete; + public List postList; + public List editalbeAccounts; + // write in the konto dates of user and will be overwritten everytime the + // account changes + public static String[] userInfos = new String[7]; + // to save the current data of the user + public static String userTmpInfos = ""; + private JFrame mainframe, frameEditable; + public File[] files; + public static File f = new File( + "/home/helex/NetBeansProjects/Test2/src/"); + public static String dir = "/home/helex/NetBeansProjects/Test2/src/"; + public String currentUserDir = ""; + + // display main-frame of the client + public void createMainFrame() { + mainframe = new JFrame("Email-Client"); + mainframe.setVisible(false); + mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + mainframe.setSize(800, 600); + + // user can change the size of the window + mainframe.setResizable(true); + + // create the file menu + file = new Menu("File"); + readmail = new MenuItem("Read Emails"); + file.add(readmail); + readmail.addActionListener(new ReadMailListener()); + writemail = new MenuItem("Write Email"); + file.add(writemail); + writemail.addActionListener(new WriteMailListener()); + file.addSeparator(); + managelocalfiles = new MenuItem("Manage Emails"); + managelocalfiles.addActionListener(new MangeMailsListener()); + file.add(managelocalfiles); + file.addSeparator(); + + exit = new MenuItem("Quit"); + file.add(exit); + exit.addActionListener(new ExitItemListener()); + + info = new Menu("Info"); + info.add("Info"); + info.addActionListener(new InfoListener()); + + menucomplete = new MenuBar(); + menucomplete.add(file); + menucomplete.add(accounts); + menucomplete.add(info); + + mainframe.setMenuBar(menucomplete); + + mainframe.setVisible(true); + } + + // the fucking Listeners + class InfoListener implements ActionListener { + + public void actionPerformed(ActionEvent e) { + Frame test = new JFrame("Mail-Client Infos"); + JPanel aboutPanel = new JPanel(); + aboutPanel.setLayout(new GridLayout(4, 1)); + test.setSize(400, 200); + JLabel about = new JLabel( + "Mail-Client: Designt by Matthias Guenther"); + JLabel about1 = new JLabel("Version: 2.0"); + JLabel about2 = new JLabel("Contact: lordmatze@googlemail.com"); + JLabel about3 = new JLabel( + "Performed in the 'Programmierpraktikum 2, SS 2007'"); + aboutPanel.add(about); + aboutPanel.add(about1); + aboutPanel.add(about2); + aboutPanel.add(about3); + test.add(aboutPanel); + test.setVisible(true); + } + } + + class ReadMailListener implements ActionListener { + + public void actionPerformed(ActionEvent arg0) { + GUIMailsget test = new GUIMailsget(); + test.guiMailsget(); + } + } + + class WriteMailListener implements ActionListener { + + public void actionPerformed(ActionEvent arg0) { + GUIMailsend send = new GUIMailsend(); + send.guiMailsend(); + } + } + + class ExitItemListener implements ActionListener { + + public void actionPerformed(ActionEvent arg0) { + System.exit(0); + } + } + + class NewAccountListener implements ActionListener { + + public void actionPerformed(ActionEvent arg0) { + GUIKontoInformation test = new GUIKontoInformation(); + test.GUIKontoInformationCreate(); + } + } + + class MangeMailsListener implements ActionListener { + + public void actionPerformed(ActionEvent arg0) { + try { + GUITreeInsert treeFrame = new GUITreeInsert(); + treeFrame.setSize(400, 400); + treeFrame.setVisible(true); + } catch (Exception e) { + System.out.println(e); + } + + } + } + + // to list alle available Accounts + public void searchAccounts(File dir) throws IOException { + files = dir.listFiles(); + accounts = new Menu("Account(s)"); + accountnew = new MenuItem("New Account"); + accountnew.addActionListener(new NewAccountListener()); + accountedit = new MenuItem("Edit Account"); + accountedit.addActionListener(new EditAccountListener()); + accounts.add(accountnew); + accounts.add(accountedit); + accounts.addSeparator(); + if (files != null) { + for (int i = 0; i < files.length; i++) { + + String tmp = files[i].getAbsolutePath(); + + if (tmp.endsWith("kondat")) { + String tmpinfos = ""; + FileReader f = new FileReader(tmp); + for (int c; (c = f.read()) != -1;) { + tmpinfos = tmpinfos + (char) c; + } + + userInfos = tmpinfos.split("#######"); + accountavailable = new MenuItem(userInfos[1]); + accountavailable.addActionListener(new accountlistener()); + accounts.add(accountavailable); + + } + + } + + } + + } + + class accountlistener implements ActionListener { + + public void actionPerformed(ActionEvent e) { + // dirty cast to get name of the Label + String name = ((MenuItem) e.getSource()).getLabel(); + + FileReader file = null; + String tmp = ""; + try { + file = new FileReader(dir + name + " kontoinfos.kondat"); + + for (int c; (c = file.read()) != -1;) { + tmp = tmp + (char) c; + } + + userInfos = tmp.split("#######"); + + } catch (IOException es) { + System.out.println("Error reading file!"); + } finally { + try { + file.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + + } + + } + } + + class EditAccountListener implements ActionListener { + + public void actionPerformed(ActionEvent arg0) { + try { + + editableAccounts(f); + + } catch (IOException e) { + e.printStackTrace(); + } + + } + } + + // to list all available editable accounts + public void editableAccounts(File dir) throws IOException { + frameEditable = new JFrame("Editable Accounts"); + editalbeAccounts = new List(); + frameEditable.setSize(200, 200); + frameEditable.setLayout(new BorderLayout()); + edit = new JLabel("Available Accounts: "); + frameEditable.add(edit, "North"); + JPanel tmpe = new JPanel(); + files = dir.listFiles(); + if (files != null) { + for (int i = 0; i < files.length; i++) { + + String tmp = files[i].getAbsolutePath(); + + if (tmp.endsWith("kondat")) { + String tmpinfos = ""; + FileReader f = new FileReader(tmp); + for (int c; (c = f.read()) != -1;) { + tmpinfos = tmpinfos + (char) c; + } + userInfos = tmpinfos.split("#######"); + editalbeAccounts.add(userInfos[1]); + + tmpe.add(editalbeAccounts, "Center"); + + } + + } + + } + editalbeAccounts.addItemListener(new EditListener()); + frameEditable.add(tmpe); + frameEditable.setVisible(true); + + } + + class EditListener implements ItemListener { + + public void itemStateChanged(ItemEvent e) { + String tmp2[] = e.getSource().toString().split("="); + String tmp1 = tmp2[1].replace("]", ""); + FileReader file = null; + String tmp = ""; + try { + file = new FileReader( + "/home/helex/NetBeansProjects/Test2/src/" + tmp1 + " kontoinfos.kondat"); + + for (int c; (c = file.read()) != -1;) { + tmp = tmp + (char) c; + } + + userInfos = tmp.split("#######"); + + } catch (IOException es) { + System.out.println("Error reading file!"); + } finally { + try { + file.close(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + } + + // close the editableAccount frame + frameEditable.setVisible(false); + + System.out.println(userInfos[0]); + GUIKontoInformation test = new GUIKontoInformation(); + test.emailadressinput.setText(userInfos[0]); + test.usernameinput.setText(userInfos[1]); + test.uservalidationnameinput.setText(userInfos[2]); + test.userpassinput.setText(userInfos[3]); + test.postentranceinput.setText(userInfos[4]); + test.postexitinput.setText(userInfos[6]); + test.GUIKontoInformationCreate(); + } + } + + // needed for the class GUIMailsget + class ComplexCellRenderer implements ListCellRenderer { + + protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer(); + + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + Font theFont = null; + Color theForeground = null; + Icon theIcon = null; + String theText = null; + + JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, + isSelected, cellHasFocus); + + if (value instanceof Object[]) { + Object values[] = (Object[]) value; + theFont = (Font) values[0]; + theForeground = (Color) values[1]; + theIcon = (Icon) values[2]; + theText = (String) values[3]; + } else { + theFont = list.getFont(); + theForeground = list.getForeground(); + theText = ""; + } + if (!isSelected) { + renderer.setForeground(theForeground); + } + if (theIcon != null) { + renderer.setIcon(theIcon); + } + renderer.setText(theText); + renderer.setFont(theFont); + return renderer; + } + } + + // needet for GUIMailsget for the icon color + class DiamondIcon implements Icon { + + private Color color; + private boolean selected; + private int width; + private int height; + private Polygon poly; + private static final int DEFAULT_WIDTH = 10; + private static final int DEFAULT_HEIGHT = 10; + + public DiamondIcon(Color color) { + this(color, true, DEFAULT_WIDTH, DEFAULT_HEIGHT); + } + + public DiamondIcon(Color color, boolean selected) { + this(color, selected, DEFAULT_WIDTH, DEFAULT_HEIGHT); + } + + public DiamondIcon(Color color, boolean selected, int width, int height) { + this.color = color; + this.selected = selected; + this.width = width; + this.height = height; + initPolygon(); + } + + private void initPolygon() { + poly = new Polygon(); + int halfWidth = width / 2; + int halfHeight = height / 2; + poly.addPoint(0, halfHeight); + poly.addPoint(halfWidth, 0); + poly.addPoint(width, halfHeight); + poly.addPoint(halfWidth, height); + } + + public int getIconHeight() { + return height; + } + + public int getIconWidth() { + return width; + } + + public void paintIcon(Component c, Graphics g, int x, int y) { + g.setColor(color); + g.translate(x, y); + if (selected) { + g.fillPolygon(poly); + } else { + g.drawPolygon(poly); + } + g.translate(-x, -y); + } + } + + public static void main(String[] args) { + try { + + GUIMain test = new GUIMain(); + + // create the search path + test.searchAccounts(f); + test.createMainFrame(); + + } catch (Exception msg) { + System.out.println(msg); + } + + } +} diff --git a/GUITreeInsert.java b/GUITreeInsert.java new file mode 100755 index 0000000..2c6ed93 --- /dev/null +++ b/GUITreeInsert.java @@ -0,0 +1,239 @@ + +import java.awt.*; +import java.awt.dnd.DropTarget; +import java.awt.dnd.DropTargetAdapter; +import java.awt.dnd.DropTargetDropEvent; +import java.awt.event.*; +import java.io.File; +import javax.swing.*; +import javax.swing.tree.*; + +/* + * Version 2.0 + * Matthias Guenther + * drag'n drop Baum zur Mail-Verwaltung + */ +public class GUITreeInsert extends JFrame implements ActionListener { + + protected DefaultMutableTreeNode root; + protected DefaultTreeModel treeModel; + protected JTree tree; + public JLabel file; + public JTextArea filename; + public JButton namefile; + public JFrame filenewFrame; + private String tmp = "d"; + public TreePath tp, sourcePath; + public DefaultMutableTreeNode node; + public DefaultMutableTreeNode selectedNode; + public DefaultMutableTreeNode goal; + public DefaultMutableTreeNode Messages; + + // create Jtree with one selection + public GUITreeInsert() { + root = new DefaultMutableTreeNode("Root"); + + // search for current Ordners + directorieSearch(); + + // create the new tree model where every node can have children + treeModel = new DefaultTreeModel(root); + tree = new JTree(treeModel); + + tree.setDragEnabled(true); + tree.getSelectionModel().setSelectionMode( + TreeSelectionModel.SINGLE_TREE_SELECTION); + // activate the drop function + tree.setDropMode(DropMode.USE_SELECTION); + tree.setVisible(true); + tree.setDropTarget(new DropTarget(tree, TransferHandler.MOVE, + new DropTargetAdapter() { + + public void drop(DropTargetDropEvent dtde) { + + TreePath selectionPath = tree.getSelectionPath(); + + sourcePath = selectionPath.getParentPath(); + + selectedNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); + + Point dropLocation = dtde.getLocation(); + + TreePath targetPath = tree.getClosestPathForLocation( + dropLocation.x, dropLocation.y); + + System.out.println("srcPath: " + sourcePath); + + System.out.println("Parent" + sourcePath.getLastPathComponent()); + System.out.println("targetPath: " + targetPath); + + // writeContent(); + + // select node + System.out.println("selectedNode: " + selectedNode); + + if (isDropAllowed(sourcePath, targetPath, selectedNode)) { + + goal = (DefaultMutableTreeNode) targetPath.getLastPathComponent(); + DefaultMutableTreeNode targetParentNode = (DefaultMutableTreeNode) targetPath.getLastPathComponent(); + + DefaultMutableTreeNode sourceParentNode = (DefaultMutableTreeNode) sourcePath.getLastPathComponent(); + + sourceParentNode.remove(selectedNode); + + targetParentNode.add(selectedNode); + + System.out.println("Goal: " + goal); + changeEmailContent(); + dtde.dropComplete(true); + + changeEmailContent(); + tree.updateUI(); + + } else { + + System.out.println("drop: reject"); + + dtde.rejectDrop(); + + dtde.dropComplete(false); + + } + + } + + private boolean isDropAllowed(TreePath sourcePath, + TreePath targetPath, + DefaultMutableTreeNode selectedNode) { + + if (((DefaultMutableTreeNode) sourcePath.getLastPathComponent()).isLeaf()) { + } else if (targetPath.equals(sourcePath)) { + + return false; + + } + + return selectedNode.isLeaf(); + + } + }// closing new Drop + )); + + // make the root visible + tree.setRootVisible(true); + + // insert the tree in a component + Container cp = getContentPane(); + cp.add(new JScrollPane(tree), BorderLayout.CENTER); + // ButtonPanel + JPanel panel = new JPanel(new FlowLayout()); + + // create the fucking buttons + String[] buttons = new String[]{"Add File"}; + for (int i = 0; i < buttons.length; ++i) { + JButton button = new JButton(buttons[i]); + button.addActionListener(this); + panel.add(button); + } + cp.add(panel, BorderLayout.SOUTH); + } + + // for the events + public void actionPerformed(ActionEvent event) { + String cmd = event.getActionCommand(); + tp = tree.getLeadSelectionPath(); + if (tp != null) { + node = (DefaultMutableTreeNode) tp.getLastPathComponent(); + + if (cmd.equals("Add File")) { + + // create a frame for the input of the file + filenewFrame = new JFrame("File Name"); + filenewFrame.setSize(200, 200); + filenewFrame.setLayout(new GridLayout()); + + file = new JLabel("File Name: "); + filename = new JTextArea(); + namefile = new JButton("Ok"); + namefile.addActionListener(new ButtonNameFileListener()); + + filenewFrame.setVisible(true); + filenewFrame.add(file); + filenewFrame.add(filename); + filenewFrame.add(namefile); + } + + } + } + + // method to list all directories with files + public void directorieSearch() { + File driveC = new File( + "/home/helex/NetBeansProjects/Test2/src/"); + File files[] = driveC.listFiles(); + File filestmp[]; + for (int i = 0; i < files.length; i++) { + if (files[i].isDirectory() == true) { + Messages = new DefaultMutableTreeNode(files[i].getName()); + // list the messages in the directories + filestmp = files[i].listFiles(); + System.out.println(filestmp.length); + // if there are files in then mail then add leafs + if (filestmp.length != 0) { + for (int j = 0; j < filestmp.length; j++) { + System.out.println("1"); + Messages.add(new DefaultMutableTreeNode(filestmp[j].getName())); + } + + root.add(Messages); + } else { + // to add empty files + root.add(Messages); + } + + } + + } + + } + + // this method will be invoked, if the user changes the positions of the + // messages + public void changeEmailContent() { + File source = new File( + "/home/helex/NetBeansProjects/Test2/src/" + sourcePath.getLastPathComponent() + "/" + selectedNode); + File ziel = new File( + "/home/helex/NetBeansProjects/Test2/src/" + goal + "/" + selectedNode); + + source.renameTo(ziel); + + } + + // listener if the user add a directory + class ButtonNameFileListener implements ActionListener { + + public void actionPerformed(ActionEvent evt) { + filenewFrame.setVisible(false); + tmp = filename.getText(); + DefaultMutableTreeNode child; + child = new DefaultMutableTreeNode(tmp); + File userName = new File(child.toString()); + userName.mkdir(); + treeModel.insertNodeInto(child, node, node.getChildCount()); + TreeNode[] path = treeModel.getPathToRoot(node); + tree.expandPath(new TreePath(path)); + } + } + + public static void main(String[] args) { + try { + GUITreeInsert treeFrame = new GUITreeInsert(); + treeFrame.setVisible(true); + treeFrame.setSize(300, 300); + treeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + treeFrame.setVisible(true); + } catch (Exception e) { + System.out.println(e); + } + } +} diff --git a/Inbox MG/Fri Aug 14 18_52_59 CEST 2009.txt b/Inbox MG/Fri Aug 14 18_52_59 CEST 2009.txt new file mode 100755 index 0000000..e76e107 --- /dev/null +++ b/Inbox MG/Fri Aug 14 18_52_59 CEST 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: Condor +[SUBJECT]: Condor Reisebestätigung 9379598 +[CONTENT]: javax.mail.internet.MimeMultipart@10e3293 \ No newline at end of file diff --git a/Inbox MG/Fri Dec 26 10_42_10 CET 2008.txt b/Inbox MG/Fri Dec 26 10_42_10 CET 2008.txt new file mode 100755 index 0000000..d4975b1 --- /dev/null +++ b/Inbox MG/Fri Dec 26 10_42_10 CET 2008.txt @@ -0,0 +1,4 @@ +True +[FROM]: =?ISO-8859-15?Q?Wolfgang_G=FCnther?= +[SUBJECT]: Klassentreffen 2009 Jeschkental +[CONTENT]: javax.mail.internet.MimeMultipart@1df5a8f \ No newline at end of file diff --git a/Inbox MG/Mon Aug 29 17_15_19 CEST 2005.txt b/Inbox MG/Mon Aug 29 17_15_19 CEST 2005.txt new file mode 100755 index 0000000..87c08b1 --- /dev/null +++ b/Inbox MG/Mon Aug 29 17_15_19 CEST 2005.txt @@ -0,0 +1,4 @@ +True +[FROM]: Herbert Hesse +[SUBJECT]: Aktuelle Adressenliste A1/76 +[CONTENT]: javax.mail.internet.MimeMultipart@b01d43 \ No newline at end of file diff --git a/Inbox MG/Mon Jun 08 17_22_41 CEST 2009.txt b/Inbox MG/Mon Jun 08 17_22_41 CEST 2009.txt new file mode 100755 index 0000000..1034ea6 --- /dev/null +++ b/Inbox MG/Mon Jun 08 17_22_41 CEST 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: =?ISO-8859-15?Q?Sebastian_G=FCnther?= +[SUBJECT]: SG Jahresziele W21-23 +[CONTENT]: javax.mail.internet.MimeMultipart@2e7820 \ No newline at end of file diff --git a/Inbox MG/Sat Feb 28 10_41_20 CET 2009.txt b/Inbox MG/Sat Feb 28 10_41_20 CET 2009.txt new file mode 100755 index 0000000..6dd340b --- /dev/null +++ b/Inbox MG/Sat Feb 28 10_41_20 CET 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: =?ISO-8859-15?Q?Sebastian_G=FCnther?= +[SUBJECT]: Jahresziele W8 und W9 +[CONTENT]: javax.mail.internet.MimeMultipart@bfea1d \ No newline at end of file diff --git a/Inbox MG/Sat Feb 28 10_46_22 CET 2009.txt b/Inbox MG/Sat Feb 28 10_46_22 CET 2009.txt new file mode 100755 index 0000000..8002fab --- /dev/null +++ b/Inbox MG/Sat Feb 28 10_46_22 CET 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: =?ISO-8859-15?Q?Sebastian_G=FCnther?= +[SUBJECT]: Landkarte zur Zielerreichung +[CONTENT]: javax.mail.internet.MimeMultipart@dc6a77 \ No newline at end of file diff --git a/Inbox MG/Sun Aug 16 10_52_05 CEST 2009.txt b/Inbox MG/Sun Aug 16 10_52_05 CEST 2009.txt new file mode 100755 index 0000000..1e3afd2 --- /dev/null +++ b/Inbox MG/Sun Aug 16 10_52_05 CEST 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: "reiselinie.de" +[SUBJECT]: Reisebestätigung/Rechnung GUENTHER 11.03.2010 SSH 12397332 +[CONTENT]: javax.mail.internet.MimeMultipart@fe748f \ No newline at end of file diff --git a/Inbox MG/Sun May 17 12_45_40 CEST 2009.txt b/Inbox MG/Sun May 17 12_45_40 CEST 2009.txt new file mode 100755 index 0000000..977cee0 --- /dev/null +++ b/Inbox MG/Sun May 17 12_45_40 CEST 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: "PARKundSPAR.de" +[SUBJECT]: PARKundSPAR.de - Ihre Buchung:44832 / Sonntag, 17. Mai 2009 +[CONTENT]: javax.mail.internet.MimeMultipart@861f24 \ No newline at end of file diff --git a/Inbox MG/Thu Jan 01 11_37_47 CET 2009.txt b/Inbox MG/Thu Jan 01 11_37_47 CET 2009.txt new file mode 100755 index 0000000..d5456b3 --- /dev/null +++ b/Inbox MG/Thu Jan 01 11_37_47 CET 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: service@tk-online.de +[SUBJECT]: TK-Exklusiv - Ihre Registrierung +[CONTENT]: javax.mail.internet.MimeMultipart@406199 \ No newline at end of file diff --git a/Inbox MG/Tue Jul 21 18_42_56 CEST 2009.txt b/Inbox MG/Tue Jul 21 18_42_56 CEST 2009.txt new file mode 100755 index 0000000..e6fd909 --- /dev/null +++ b/Inbox MG/Tue Jul 21 18_42_56 CEST 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: "Senseo® Reparatur-Service" +[SUBJECT]: Versand Ihrer Senseo® Kaffeemaschine [18-DE-de-IT-senseo-5065036] +[CONTENT]: javax.mail.internet.MimeMultipart@78a212 \ No newline at end of file diff --git a/Inbox MG/Wed May 06 13_16_24 CEST 2009.txt b/Inbox MG/Wed May 06 13_16_24 CEST 2009.txt new file mode 100755 index 0000000..f3c9bea --- /dev/null +++ b/Inbox MG/Wed May 06 13_16_24 CEST 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: info@reiselinie.de +[SUBJECT]: Hallo Herr Guenther. Ihre Reiseanmeldung! +[CONTENT]: javax.mail.internet.MimeMultipart@11e1e67 \ No newline at end of file diff --git a/Inbox MG/Wed May 06 13_39_53 CEST 2009.txt b/Inbox MG/Wed May 06 13_39_53 CEST 2009.txt new file mode 100755 index 0000000..90ba194 --- /dev/null +++ b/Inbox MG/Wed May 06 13_39_53 CEST 2009.txt @@ -0,0 +1,4 @@ +True +[FROM]: Joachim Guenther +[SUBJECT]: Re: Hallo Herr Guenther. Ihre Reiseanmeldung! +[CONTENT]: javax.mail.internet.MimeMultipart@10ab323 \ No newline at end of file diff --git a/MG kontoinfos.kondat b/MG kontoinfos.kondat new file mode 100755 index 0000000..6e79b25 --- /dev/null +++ b/MG kontoinfos.kondat @@ -0,0 +1 @@ +razinger@web.de#######MG#######razinger#######Ratzinger#######pop3.web.de#######110#######smtp.web.de#######587 diff --git a/MailApi.java b/MailApi.java new file mode 100755 index 0000000..8261453 --- /dev/null +++ b/MailApi.java @@ -0,0 +1,120 @@ + +import java.util.*; +import java.io.*; +import javax.mail.*; + +/** + * @since 04.05.2007 + * @author Matthias Guenther + * @version 1.0 + * get emails with Mailapi + */ +public class MailApi { + + // user informations + private String userId; + private String userPass; + private String connectURL; + private boolean checkOn = true; + // Readers are visible for all methods + private BufferedReader user; + + public void getConnection() { + try { + System.out.println("Insert the adress of the POP3-Server: "); + user = new BufferedReader(new InputStreamReader(System.in)); + // Beispiel: pop3.web.de + connectURL = user.readLine(); + getUser(); + + } catch (Exception msg) { + System.out.println("\nHost is not available - try again later"); + } + + } + + public void getUser() { + try { + System.out.println("\nInput your username"); + System.out.println("---------------------"); + userId = user.readLine(); + + getUserPass(); + } catch (Exception msg) { + } + + } + + public void getUserPass() { + try { + System.out.println("\nInput your password"); + System.out.println("---------------------"); + userPass = user.readLine(); + terminalApi(); + } catch (Exception msg) { + } + + } + + public void terminalApi() { + + try { + + Session session = Session.getInstance(new Properties()); + // get a Store object + Store store = session.getStore("pop3"); + store.connect(connectURL, userId, userPass); + + // get "INBOX" + Folder folder = store.getFolder("INBOX"); + folder.open(Folder.READ_WRITE); + int count = folder.getMessageCount(); + + System.out.println(count + " new messages"); + Message[] message = folder.getMessages(); + Message msg; + for (int i = 1; i <= message.length; i++) { + msg = message[i - 1]; + System.out.println("Message number: " + i); + System.out.println("Date: " + msg.getSentDate()); + } + + do { + System.out.println("Which Message do you want to read? (Quit with Q)"); + String terminalInput = user.readLine(); + if (terminalInput.startsWith("Q")) { + System.out.println("Sayonara"); + checkOn = false; + } + int number = Integer.parseInt(terminalInput); + if (number <= count && number > 0) { + Message m = folder.getMessage(number); + System.out.println("\nMessage number : " + m.getMessageNumber()); + System.out.println("Subject : " + m.getSubject()); + System.out.println("From : " + m.getFrom()[0]); + System.out.println("Content: " + m.getContent()); + System.out.println(m.getSize()); + + } else { + System.out.println("Your Input is invalid"); + } + } while (checkOn == true); + + // keep messages on server + folder.close(false); + store.close(); + + } catch (IOException msg) { + System.out.println(msg); + } catch (MessagingException msg) { + System.out.println(msg); + } + + } + + public static void main(String[] args) { + MailApi userOne = new MailApi(); + userOne.getConnection(); + + } +} diff --git a/README.md b/README.md index 43e05f5..fab3e54 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ in Java. This here is the collection of my code. ## Installation for Netbeans ## -- just get the [source from github](url "zip from github") and extract it -- also extract the *javamail-1.4.zip* => this package contains a Java library for handling emails +- get the [source from github](url ) +- extract the *javamail-1.4.zip* => this package contains a Java library for handling emails - create a new project under NetBeans and copy all files of the *Mail Client* directory in the *src* directory of you NetBeans project - then you have to insert the *mail.jar* file in your project in the following way: