// log.info("startup parameters {mailarchivaserver='"+mailArchivaServerURL.getHost()+"',mailServer='"+mailURL.getHost()+"',
// pollinterval='"+interval/1000+" sec'}");
log.info("startup parameters {mailarchivaserver='" + mailArchivaServerURL.getHost() + "',mailServer='" + mailServerURL
+ "', pollinterval='" + interval / 1000 + " sec'}");
MailArchiva mailArchiva = null;
try
{
MailArchivaService service = new MailArchivaServiceLocator();
mailArchiva = service.getMailArchiva(mailArchivaServerURL);
}
catch (Exception e)
{
log.error("failed to connect to mailarchiva server {url='" + mailArchivaServerURL.getHost() + "'}", e);
System.exit(1);
}
IAPAgent IAPAgent = new IAPAgent(mailServerURL);
while (!exit)
{
log.info("connecting to email server {url='" + mailServerURL + "'}");
try
{
IAPAgent.connect();
}
catch (Exception e)
{
log.error("failed to connect to email server {popserver='" + mailServerURL + "'}", e);
System.exit(1);
}
int messageCount = 0;
int unreadCount = 0;
try
{
messageCount = IAPAgent.getMessageCount();
unreadCount = IAPAgent.getUnreadMessageCount();
}
catch (Exception e)
{
log.error("failed to retrieve no. of messages in the default inbox", e);
System.exit(1);
}
log.info("connected to mail server {totmsgs='" + messageCount + "',unreadmsgs='" + unreadCount + "'}");
for (int i = 1; i <= messageCount; i++)
{
try
{
MimeMessage m = (MimeMessage) IAPAgent.getMessage(i);
Address from[] = m.getFrom();
log.info("store message {from='" + from[0].toString() + "',subject='" + m.getSubject() + "'}");
// FileOutputStream fos = new FileOutputStream("test.eml");
// m.writeTo(fos);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gs = new GZIPOutputStream(baos);
m.writeTo(gs);
gs.finish();
mailArchiva.storeMessage(baos.toByteArray());
// m.setFlag(Flag.DELETED, true);
}
catch (Exception e)
{
log.error("failed to store message", e);