|
|
|
|
@ -12,11 +12,14 @@ 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.FileInputStream;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
|
|
import javax.swing.AbstractAction;
|
|
|
|
|
@ -61,7 +64,7 @@ public class MailDialog extends CustomJDialog
|
|
|
|
|
protected JTextField bccText;
|
|
|
|
|
protected JTextField subjectText;
|
|
|
|
|
protected BaseTable attachmentsTable;
|
|
|
|
|
protected VectorTableModel attachmentsModel;
|
|
|
|
|
protected VectorTableModel<String> attachmentsModel;
|
|
|
|
|
protected JTextPane bodyPane;
|
|
|
|
|
|
|
|
|
|
protected Action removeAttachmentAction;
|
|
|
|
|
@ -109,7 +112,7 @@ public class MailDialog extends CustomJDialog
|
|
|
|
|
System.exit( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MailDialog( JFrame owner, String to, String bcc, String subject, String message )
|
|
|
|
|
public MailDialog( JFrame owner, String to, String bcc, String subject, String message, Vector<File> files )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
super( owner, true );
|
|
|
|
|
@ -119,6 +122,7 @@ public class MailDialog extends CustomJDialog
|
|
|
|
|
setBcc( bcc );
|
|
|
|
|
setSubject( subject );
|
|
|
|
|
setMessage( message );
|
|
|
|
|
attach( files );
|
|
|
|
|
setModal( true );
|
|
|
|
|
setSize( 1024, 768 );
|
|
|
|
|
setVisible( true );
|
|
|
|
|
@ -194,10 +198,7 @@ public class MailDialog extends CustomJDialog
|
|
|
|
|
if( filename != null )
|
|
|
|
|
{
|
|
|
|
|
String dir = fd.getDirectory();
|
|
|
|
|
String full = filename + " (" + dir + ")";
|
|
|
|
|
Vector values = attachmentsModel.getValues();
|
|
|
|
|
values.add( full );
|
|
|
|
|
attachmentsModel.setValues( values );
|
|
|
|
|
attach( filename, dir );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@ -242,10 +243,10 @@ public class MailDialog extends CustomJDialog
|
|
|
|
|
bccText.setEditable( false );
|
|
|
|
|
JLabel assuntoLabel = new JLabel( "Assunto:" );
|
|
|
|
|
subjectText = new JTextField();
|
|
|
|
|
attachmentsModel = new VectorTableModel( new String[]{ "" } );
|
|
|
|
|
attachmentsModel = new VectorTableModel<String>( new String[]{ "" } );
|
|
|
|
|
attachmentsTable = new BaseTable( attachmentsModel );
|
|
|
|
|
JScrollPane attachmentsScroll = new JScrollPane( attachmentsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
|
|
|
|
|
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
|
|
|
|
|
// JScrollPane attachmentsScroll = new JScrollPane( attachmentsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
|
|
|
|
|
// JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
|
|
|
|
|
attachmentsTable.getSelectionModel().addListSelectionListener( new ListSelectionListener(){
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -529,47 +530,52 @@ public class MailDialog extends CustomJDialog
|
|
|
|
|
String subject = subjectText.getText();
|
|
|
|
|
String body = bodyPane.getText();
|
|
|
|
|
String attachmentList[] = new String[ attachmentsTable.getRowCount() ];
|
|
|
|
|
byte attachments[][] = new byte[ attachmentsTable.getRowCount() ][];
|
|
|
|
|
Vector values = attachmentsModel.getValues();
|
|
|
|
|
List<File> attachments = new LinkedList<File>();
|
|
|
|
|
Vector<String> values = attachmentsModel.getValues();
|
|
|
|
|
for( int n = 0; n < attachmentList.length; n++ )
|
|
|
|
|
{
|
|
|
|
|
String str = ( String ) values.elementAt( n );
|
|
|
|
|
String str = values.elementAt( n );
|
|
|
|
|
String name = str.substring( 0, str.indexOf( "(") - 1 );
|
|
|
|
|
String path = str.substring( str.indexOf( "(") + 1, str.indexOf( ")") );
|
|
|
|
|
try
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
File file = new File(path + name);
|
|
|
|
|
if( file != null && file.exists() )
|
|
|
|
|
{
|
|
|
|
|
FileInputStream fis = new FileInputStream( path + name );
|
|
|
|
|
Vector<byte[]> bytes = new Vector<byte[]>();
|
|
|
|
|
int available = 0;
|
|
|
|
|
int total = 0;
|
|
|
|
|
while( ( available = fis.available() ) > 0 )
|
|
|
|
|
{
|
|
|
|
|
byte b[] = new byte[ available ];
|
|
|
|
|
fis.read( b );
|
|
|
|
|
bytes.add( b );
|
|
|
|
|
total += available;
|
|
|
|
|
}
|
|
|
|
|
attachments[ n ] = new byte[ total ];
|
|
|
|
|
int pos = 0;
|
|
|
|
|
for( byte[] chunk : bytes )
|
|
|
|
|
{
|
|
|
|
|
System.arraycopy( chunk, 0, attachments[ n ], pos, chunk.length );
|
|
|
|
|
pos += chunk.length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch( FileNotFoundException fnfex )
|
|
|
|
|
{
|
|
|
|
|
JOptionPane.showMessageDialog( owner,
|
|
|
|
|
"O ficheiro " + path + name + " n\u00e3o existe.",
|
|
|
|
|
"Ficheiro inexistente",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
catch( IOException ioex )
|
|
|
|
|
{
|
|
|
|
|
DialogException.showExceptionMessage( ioex, "Erro a ler ficheiro " + path + name, true );
|
|
|
|
|
return;
|
|
|
|
|
attachments.add(file);
|
|
|
|
|
}
|
|
|
|
|
// FileInputStream fis = new FileInputStream( path + name );
|
|
|
|
|
// Vector<byte[]> bytes = new Vector<byte[]>();
|
|
|
|
|
// int available = 0;
|
|
|
|
|
// int total = 0;
|
|
|
|
|
// while( ( available = fis.available() ) > 0 )
|
|
|
|
|
// {
|
|
|
|
|
// byte b[] = new byte[ available ];
|
|
|
|
|
// fis.read( b );
|
|
|
|
|
// bytes.add( b );
|
|
|
|
|
// total += available;
|
|
|
|
|
// }
|
|
|
|
|
// attachments[ n ] = new byte[ total ];
|
|
|
|
|
// int pos = 0;
|
|
|
|
|
// for( byte[] chunk : bytes )
|
|
|
|
|
// {
|
|
|
|
|
// System.arraycopy( chunk, 0, attachments[ n ], pos, chunk.length );
|
|
|
|
|
// pos += chunk.length;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// catch( FileNotFoundException fnfex )
|
|
|
|
|
// {
|
|
|
|
|
// JOptionPane.showMessageDialog( owner,
|
|
|
|
|
// "O ficheiro " + path + name + " n\u00e3o existe.",
|
|
|
|
|
// "Ficheiro inexistente",
|
|
|
|
|
// JOptionPane.ERROR_MESSAGE );
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// catch( IOException ioex )
|
|
|
|
|
// {
|
|
|
|
|
// DialogException.showExceptionMessage( ioex, "Erro a ler ficheiro " + path + name, true );
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
MailSender sender = new MailSender();
|
|
|
|
|
try
|
|
|
|
|
@ -593,4 +599,20 @@ public class MailDialog extends CustomJDialog
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void attach( Vector<File> files )
|
|
|
|
|
{
|
|
|
|
|
for (File file : files )
|
|
|
|
|
{
|
|
|
|
|
attach( file.getName(), file.getParent() + File.separator );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void attach( String filename, String dir )
|
|
|
|
|
{
|
|
|
|
|
String full = filename + " (" + dir + ")";
|
|
|
|
|
Vector<String> values = attachmentsModel.getValues();
|
|
|
|
|
values.add( full );
|
|
|
|
|
attachmentsModel.setValues( values );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|