/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* finestra.java
*
* Created on 24-apr-2009, 16.58.31
*/
package riceviemail;
import java.io.*;
import java.net.*;
import javax.swing.text.html.HTMLEditorKit;
/**
*
* @author Administrator
*/
public class Finestra
extends javax.
swing.
JFrame {
/** Creates new form finestra */
private static final int porta = 110;
private static Socket connect
;
pass,
server;
public Finestra() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
username
= new javax.
swing.
JLabel();
password
= new javax.
swing.
JLabel();
serverpop3
= new javax.
swing.
JLabel();
risultati
= new javax.
swing.
JLabel();
Cancella
= new javax.
swing.
JButton();
Logout
= new javax.
swing.
JButton();
setName("EnricMailRecieved"); // NOI18N
username.setText("User Es. \"mario@virgilio.it\"");
password.setText("Pass Es. \"pippobaubau\"");
Test.setText("TestConnessione");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
TestConnessioneAction(evt);
}
});
serverpop3.setText("Server POP3 Es. \"in.virgilio.it\"");
Login.setText("LogIn");
Login.setEnabled(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
LoginAction(evt);
}
});
anteprima.
setFont(new java.
awt.
Font("Arial", 0, 9
));
Apri.setText("Apri");
Apri.setEnabled(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
ApriAction(evt);
}
});
Cancella.setText("Cancella");
Cancella.setEnabled(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
CancellaAction(evt);
}
});
Logout.setText("LogOut");
Logout.setEnabled(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
LogoutAction(evt);
}
});
VisMail.setEditable(false);
jScrollPane1.setViewportView(VisMail);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(96, 96, 96)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(Pass)
.addComponent(Server)
.
addComponent(User, javax.
swing.
GroupLayout.
DEFAULT_SIZE, 154,
Short.
MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(8, 8, 8)
.addComponent(Test)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(Login)
.addGap(18, 18, 18)
.addComponent(Logout))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.
addComponent(password, javax.
swing.
GroupLayout.
Alignment.
LEADING, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.
addComponent(serverpop3, javax.
swing.
GroupLayout.
Alignment.
LEADING, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(Apri, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(36, 36, 36)
.addComponent(Cancella))
.addGroup(layout.createSequentialGroup()
.addGap(38, 38, 38)
.addComponent(risultati, javax.swing.GroupLayout.PREFERRED_SIZE, 430, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(46, 46, 46))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.
addComponent(anteprima, 0, 494,
Short.
MAX_VALUE)
.addContainerGap())
.
addComponent(jScrollPane1, javax.
swing.
GroupLayout.
DEFAULT_SIZE, 514,
Short.
MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(User, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(username))
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Pass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(password))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Server, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(serverpop3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Test)
.addComponent(Login)
.addComponent(Logout))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(risultati, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(anteprima, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Apri)
.addComponent(Cancella))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
.
addContainerGap(40,
Short.
MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void TestConnessioneAction
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_TestConnessioneAction
user = User.getText();
pass = Pass.getText();
server = Server.getText();
boolean conn = connessione.controllo(server, user, pass);
if(conn)
{
risultati.setText("Dati inseriti correttamente! Effettua il Login!");
Login.setEnabled(true);
}else{
risultati.setText("Dati inseriti non corretti! Prego controllare i dati!");
Login.setEnabled(false);
}
}//GEN-LAST:event_TestConnessioneAction
private void LoginAction
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_LoginAction
user = User.getText();
pass = Pass.getText();
server = Server.getText();
try{
CreaStream();
if(connessione.login(dalServer, alServer, user, pass))
{
Logout.setEnabled(true);
Apri.setEnabled(true);
Cancella.setEnabled(true);
VisMail.setText("");
int numMail = Mail.contaMail(dalServer,alServer);
System.
out.
println("Letto Numero Mail");
for(int i=1; i<=numMail;i++)
{
//* Opzione 0 = Mittente
//* Opzione 1 = Oggetto
//* Opzione 2 = Messaggio
/*String mittente = Mail.mail(dalServer, alServer, i, 0),
oggetto = Mail.mail(dalServer, alServer, i, 1);
*/
String mittente
= Mail.
leggiMittente(dalServer, alServer, i
),
oggetto = Mail.leggiOggetto(dalServer, alServer, i);
anteprima.addItem(i+": Mittente: "+mailMittente(mittente)+" Oggetto: "+oggetto);
System.
out.
println("Letta con successo mail numero "+i
);
}
}else{
risultati.setText("Errore nel Login! Controllare i dati!");
Login.setEnabled(false);
Logout.setEnabled(false);
Apri.setEnabled(false);
Cancella.setEnabled(false);
VisMail.setText("");
anteprima.removeAllItems();
}
{
risultati.setText("Errore connessione! Controllare la connessione!");
Login.setEnabled(false);
Logout.setEnabled(false);
Apri.setEnabled(false);
Cancella.setEnabled(false);
VisMail.setText("");
anteprima.removeAllItems();
}
}//GEN-LAST:event_LoginAction
private void LogoutAction
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_LogoutAction
connessione.logout(dalServer,alServer);
Login.setEnabled(false);
Logout.setEnabled(false);
Apri.setEnabled(false);
Cancella.setEnabled(false);
VisMail.setText("");
risultati.setText("LogOut effettuato!");
}//GEN-LAST:event_LogoutAction
private void CancellaAction
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_CancellaAction
int n = anteprima.getSelectedIndex();
VisMail.setText("");
System.
out.
println("Stai cancellando la Mail n° "+(n
+1
));
if(!connessione.controlloLogin(dalServer, alServer))
{
CreaStream();
connessione.login(dalServer, alServer, user, pass);
}
if(Mail.cancellaMail(dalServer, alServer, n+1))
{
risultati.setText("E-mail Eliminata! Verra cancellata del tutto al primo LogOut!");
anteprima.removeItemAt(n);
}else{
risultati.setText("Impossibile Cancellare l'e-Mail");
}
}//GEN-LAST:event_CancellaAction
private void ApriAction
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_ApriAction
int n = anteprima.getSelectedIndex();
System.
out.
println("Stai aprendo la Mail n° "+(n
+1
));
if(!connessione.controlloLogin(dalServer, alServer))
{
CreaStream();
connessione.login(dalServer, alServer, user, pass);
}
if((n+1)>Mail.contaMail(dalServer, alServer))
{
VisMail.setText("");
risultati.setText("La Mail non Esiste!");
}else{
//* Opzione 0 = Mittente
//* Opzione 1 = Oggetto
//* Opzione 2 = Messaggio
/* String mittente = Mail.mail(dalServer, alServer, n+1, 0),
oggetto = Mail.mail(dalServer, alServer, n+1, 1),
messaggio = Mail.mail(dalServer, alServer, n+1, 2);
*/
String mittente
= Mail.
leggiMittente(dalServer, alServer, n
+1
),
oggetto = Mail.leggiOggetto(dalServer, alServer, n+1),
messaggio = Mail.leggiMessaggio(dalServer, alServer, n+1);
VisMail.setText("Da : "+mittente+"<br>A : "+user+"<br><br>Oggetto : "+oggetto+"<br>---------------------------------------------------------<br>"+messaggio);
}
}//GEN-LAST:event_ApriAction
/**
* @param args the command line arguments
*/
public static void main
(String args
[]) {
public void run() {
new Finestra().setVisible(true);
}
});
}
static void CreaStream()
{
try{
connect
= new Socket(server,porta
);
System.
out.
println("Connessione creata: "+connessione.
risposta(dalServer
));
{
System.
out.
println("Impossibile creare stream!!");
}
}
{
if(mittente.charAt(mittente.length()-1)=='>')
{
mail = mittente.substring(mittente.indexOf("<")+1,mittente.length()-1);
return mail;
}else
return mittente;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.
swing.
JButton Cancella
;
private javax.
swing.
JButton Logout
;
private javax.
swing.
JLabel password
;
private javax.
swing.
JLabel risultati
;
private javax.
swing.
JLabel serverpop3
;
private javax.
swing.
JLabel username
;
// End of variables declaration//GEN-END:variables
}