
jadex.platform.service.email.SubscriptionInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-platform Show documentation
Show all versions of jadex-platform Show documentation
The Jadex platform package contains implementations of
platform services as well as the platform component itself.
The newest version!
package jadex.platform.service.email;
import jadex.bridge.service.types.email.Email;
import jadex.bridge.service.types.email.EmailAccount;
import jadex.commons.IFilter;
import jadex.commons.SUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage.RecipientType;
import javax.mail.search.FlagTerm;
/**
* Info struct for email subscriptions.
*/
public class SubscriptionInfo
{
//-------- attributes --------
/** The filter. */
protected IFilter filter;
/** The account. */
protected EmailAccount account;
/** The number of messages in the folder. */
protected int total;
protected int lastseenno;
protected Email lastseenmsg;
//-------- constructors --------
/**
* Create a new subscription info.
*/
public SubscriptionInfo(IFilter filter, EmailAccount account)
{
this.total = 0;
this.filter = filter;
this.account = account;
}
//-------- methods --------
/**
* Get the filter.
* @return The filter.
*/
public IFilter getFilter()
{
return filter;
}
/**
* Set the filter.
* @param filter The filter to set.
*/
public void setFilter(IFilter filter)
{
this.filter = filter;
}
/**
* Get the account.
* @return The account.
*/
public EmailAccount getAccount()
{
return account;
}
/**
* Set the account.
* @param account The account to set.
*/
public void setAccount(EmailAccount account)
{
this.account = account;
}
/**
* Fetch new emails from the inbox.
*/
public List getNewEmails()
{
List ret = null;
Store store = null;
try
{
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", account.getReceiveProtocol());
Session session = Session.getDefaultInstance(props, null);
store = session.getStore(account.getReceiveProtocol());
store.connect(account.getReceiveHost(), account.getUser(), account.getPassword());
Folder f = store.getFolder("inbox");
f.open(Folder.READ_ONLY);
int newtotal = f.getMessageCount();
// Rescan messages
if(lastseenno>0 && total>0)
{
// if less messages than last time
if(lastseenno>newtotal)
{
total = 0;
}
else
{
// if the position of the last seen message has changed
Message lsm = f.getMessage(lastseenno);
if(lsm!=null && !convertMessage(lsm).equals(lastseenmsg))
{
total = 0;
}
}
}
if(total0)
{
Email email = null;
ret = new ArrayList();
for(int i=0; i texts = new ArrayList();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy