package de.comu.wikiplugin; import com.ecyrd.jspwiki.WikiContext; import com.ecyrd.jspwiki.WikiEngine; import com.ecyrd.jspwiki.WikiPage; import com.ecyrd.jspwiki.plugin.PluginException; import com.ecyrd.jspwiki.plugin.WikiPlugin; import java.util.Date; import java.util.Map; import java.util.Properties; import java.io.BufferedReader; import java.io.InputStreamReader; import javax.mail.Folder; import javax.mail.Message; import javax.mail.Session; import javax.mail.Store; import javax.mail.Flags.Flag; import javax.mail.Multipart; import javax.mail.Part; import javax.mail.internet.MimeBodyPart; /** * Computer Mutter GmbH * www.comu.de * * @author Wolfgang Mutter */ public class POPmailPlugin implements WikiPlugin { public static final java.text.SimpleDateFormat DATETIMEFORMAT = new java.text.SimpleDateFormat ( "dd.MM.yyyy HH:mm:ss" ); /** * This is the main entry point for any plugin. The parameters are parsed, * and a special parameter called "_body" signifies the name of the plugin * body, i.e. the part of the plugin that is not a parameter of * the form "key=value". This has been separated using an empty * line. *
* Note that it is preferred that the plugin returns * XHTML-compliant HTML (i.e. close all tags, use <br /> * instead of <br>, etc. * * @param context The current WikiContext. * @param params A Map which contains key-value pairs. Any * parameter that the user has specified on the * wiki page will contain String-String * parameters, but it is possible that at some future date, * JSPWiki will give you other things that are not Strings. * * @return HTML, ready to be included into the rendered page. * * @throws PluginException In case anything goes wrong. */ public String execute ( WikiContext context, Map params ) throws PluginException { try { WikiEngine engine = context.getEngine (); WikiPage page = engine.getPage ( context.getPage ().getName () ); String pageData = engine.getPureText ( page ); String msg =""; Message m = null; Session session = Session.getDefaultInstance ( new Properties () ); Store store = session.getStore ( "pop3" ); store.connect ( (String)params.get ("host"),(String)params.get ("user"),(String)params.get ("pass") ); Folder folder = store.getFolder ( "INBOX" ); folder.open ( Folder.READ_WRITE ); Message message[] = folder.getMessages (); for ( int i = 0; i < message.length; i++ ) { m = message[i]; if (pageData.indexOf (""+m.getSentDate ())==-1) { msg+="__"+m.getSubject ()+"__\\\\"+DATETIMEFORMAT.format (m.getSentDate ())+" "+m.getFrom ()[0]+"\\\\\n{{{"; if(m.getContent() instanceof Multipart) { Multipart mp = (Multipart) m.getContent(); for ( int j = 0; j < mp.getCount(); j++ ) { Part part = mp.getBodyPart( j ); String disposition = part.getDisposition(); if ( disposition.equals("inline") ) { MimeBodyPart mimePart = (MimeBodyPart)part; if ( mimePart.isMimeType("text/plain") ) { BufferedReader in = new BufferedReader( new InputStreamReader(mimePart.getInputStream()) ); for ( String line; (line=in.readLine()) != null; ) msg+="\n"+ line +"\n"; } } } } else { msg+="\n"+ m.getContent()+"\n"; } // msg+="{{{"+m.getContent ().toString ()+"}}}----\n\n"; msg+="}}}----\n"; m.setFlag ( Flag.DELETED,true ); } } folder.close ( true ); store.close (); if( msg.length () > 0 ) { pageData = msg+pageData; engine.saveText (context,pageData); } return "Letzte Aktualisierung: "+DATETIMEFORMAT.format (new Date ()); } catch (Exception exp) { System.err.println (exp); throw new PluginException (exp.toString ()); } } }