Examples of MailetContext


Examples of org.apache.mailet.MailetContext

    public void init(MailetConfig config) throws MessagingException {
        this.config = config;
    }

    public void service(Mail mail) throws MessagingException {
        MailetContext context = config.getMailetContext();
        context.log("######## MAIL STARTS");
        context.log("");
       
        MimeMessage message = mail.getMessage();
       
        context.log("Mail named: " + mail.getName());
       
        for (Iterator it=mail.getAttributeNames(); it.hasNext();) {
            String attributeName = (String) it.next();
            context.log("Attribute " + attributeName);
        }
        context.log("Message size: " + mail.getMessageSize());
        context.log("Last updated: " + mail.getLastUpdated());
        context.log("Remote Address: " + mail.getRemoteAddr());
        context.log("Remote Host: " + mail.getRemoteHost());
        context.log("State: " + mail.getState());
        context.log("Sender host: " + mail.getSender().getDomain());
        context.log("Sender user: " + mail.getSender().getLocalPart());
        Collection<MailAddress> recipients = mail.getRecipients();
        for (Iterator<MailAddress> it = recipients.iterator(); it.hasNext();)
        {
            MailAddress address = it.next();
            context.log("Recipient: " + address.getLocalPart() + "@" + address.getDomain());
        }
       
        context.log("Subject: " + message.getSubject());
        context.log("MessageID: " + message.getMessageID());
        context.log("Received: " + message.getReceivedDate());
        context.log("Sent: " + message.getSentDate());
       
        Enumeration allHeadersLines = message.getAllHeaderLines();
        while(allHeadersLines.hasMoreElements()) {
            String header = (String) allHeadersLines.nextElement();
            context.log("Header Line:= " + header);
        }
       
       
        Enumeration allHeadersEnumeration = message.getAllHeaders();
        while(allHeadersEnumeration.hasMoreElements()) {
            Header header = (Header) allHeadersEnumeration.nextElement();
            context.log("Header: " + header.getName() + "=" + header.getValue());
        }
       
        Address[] to = message.getRecipients(RecipientType.TO);
        printAddresses(to, "TO: ");
        Address[] cc = message.getRecipients(RecipientType.CC);
        printAddresses(cc, "CC: ");    
        Address[] bcc = message.getRecipients(RecipientType.BCC);
        printAddresses(bcc, "BCC: ");  

       
        Flags flags = message.getFlags();
        Flag[] systemFlags = flags.getSystemFlags();
        for (int i=0;i<systemFlags.length;i++) {
            context.log("System Flag:" + systemFlags[i]);
        }
        String[] userFlags = flags.getUserFlags();
        for (int i=0;i<userFlags.length;i++) {
            context.log("User flag: " + userFlags[i]);
        }
       
        String mimeType = message.getContentType();
        context.log("Mime type: " + mimeType);
        if (mimeType == "text/plain") {
            try {
                Object content = message.getContent();
                context.log("Content: " + content);
            } catch (IOException e) {
                e.printStackTrace();
            }
           
        }
       
        context.log("");
        context.log("######## MAIL ENDS");
    }
View Full Code Here

Examples of org.apache.mailet.MailetContext

        context.log("");
        context.log("######## MAIL ENDS");
    }
   
    private final void printAddresses(Address[] addresses, String prefix) {
        MailetContext context = config.getMailetContext();
        for (int i=0;i<addresses.length;i++) {
            if (addresses[i] instanceof InternetAddress) {
                InternetAddress address = (InternetAddress) addresses[i];
                context.log(prefix + address.getPersonal() + "@" + address.getAddress());
            } else if (addresses[i] instanceof NewsAddress) {
                NewsAddress address = (NewsAddress) addresses[i];
                context.log(prefix + address.getNewsgroup() + "@" + address.getHost());
            }
        }
    }
View Full Code Here

Examples of org.apache.mailet.MailetContext

            // do the new DSN bounce
            // setting attributes for DSN mailet
            mail.setAttribute("delivery-error", ex);
            mail.setState(bounceProcessor);
            // re-insert the mail into the spool for getting it passed to the dsn-processor
            MailetContext mc = getMailetContext();
            try {
                mc.sendMail(mail);
            } catch (MessagingException e) {
                // we shouldn't get an exception, because the mail was already processed
                log("Exception re-inserting failed mail: ", e);
            }
        } else {
View Full Code Here

Examples of org.apache.mailet.MailetContext

     * @throws MessagingException if an error is encountered while modifying the message
     */
    public void service(Mail mail) throws MessagingException {
        Collection recipients = mail.getRecipients();
        Collection recipientsToRemove = null;
        MailetContext mailetContext = getMailetContext();
        boolean postmasterAddressed = false;

        for (Iterator i = recipients.iterator(); i.hasNext(); ) {
            MailAddress addr = (MailAddress)i.next();
            if (addr.getUser().equalsIgnoreCase("postmaster") &&
                mailetContext.isLocalServer(addr.getHost())) {
                //Should remove this address... we want to replace it with
                //  the server's postmaster address
                if (recipientsToRemove == null) {
                    recipientsToRemove = new Vector();
                }
View Full Code Here

Examples of org.apache.mailet.MailetContext

* @version 1.0.0, 24/04/1999
*/
public class RecipientIsLocal extends GenericRecipientMatcher {

    public boolean matchRecipient(MailAddress recipient) {
        MailetContext mailetContext = getMailetContext();
        //This might change after startup
        return mailetContext.isLocalServer(recipient.getHost())
            && mailetContext.isLocalUser(recipient.getUser());
    }
View Full Code Here

Examples of org.apache.mailet.MailetContext

     * to its check.
     *
     * @param recipient the recipient to check
     */   
    protected boolean isRecipientChecked(MailAddress recipient) throws MessagingException {
        MailetContext mailetContext = getMailetContext();
        return super.isRecipientChecked(recipient) && (mailetContext.isLocalServer(recipient.getHost()) && mailetContext.isLocalUser(recipient.getUser()));
    }
View Full Code Here

Examples of org.apache.mailet.MailetContext

    }

    private void setupMatcher() throws MessagingException {

        MailetContext mockMailContext = new MailetContext() {

            Collection localServer = new ArrayList(Arrays.asList(LOCALSERVER));

            public void bounce(Mail mail, String message)
                    throws MessagingException {
View Full Code Here

Examples of org.apache.mailet.MailetContext

    }

    private void setupMatcher() throws MessagingException {

        MailetContext mockMailContext = new MailetContext() {

            Collection localServer = new ArrayList(Arrays.asList(LOCALSERVER));

            public void bounce(Mail mail, String message)
                    throws MessagingException {
View Full Code Here

Examples of org.apache.mailet.MailetContext

            // do the new DSN bounce
            // setting attributes for DSN mailet
            mail.setAttribute("delivery-error", ex);
            mail.setState(bounceProcessor);
            // re-insert the mail into the spool for getting it passed to the dsn-processor
            MailetContext mc = getMailetContext();
            try {
                mc.sendMail(mail);
            } catch (MessagingException e) {
                // we shouldn't get an exception, because the mail was already processed
                log("Exception re-inserting failed mail: ", e);
            }
        } else {
View Full Code Here

Examples of org.apache.mailet.MailetContext

     * to its check.
     *
     * @param recipient the recipient to check
     */   
    protected boolean isRecipientChecked(MailAddress recipient) throws MessagingException {
        MailetContext mailetContext = getMailetContext();
        return super.isRecipientChecked(recipient) && (mailetContext.isLocalServer(recipient.getHost()) && mailetContext.isLocalUser(recipient.getUser()));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.