Hi,

first let me say I'm happy for this new "mail attributes" thing which was much needed 
to me, especially for Vincenzo's
matchers. 

Anyway, trying out SMTPAuthUserIs, I found that it does not work properly.
If you supply a list of (James)users as the docs say (I mean user names: postmaster, 
diego, etc), you get a mail parse exception because there is no "@" symbol. 
If you supply a mail address, it would be parsed,  but will never match because 
function getUser() (properly) returns the
user(name).

If interested, my test/fix follows.
Works fine for me.

Diego.

/******************************************************************************************************/
<mailet match="TestSMTPUser=diego,postmaster,test1" class="AddFooter">
        <text>test TestSMTPUser diego at diegomobile</text>
</mailet>

/******************************************************************************************************/
import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;
//import org.apache.mailet.MailAddress;

import java.util.Collection;
import java.util.StringTokenizer;

public class TestSMTPUser extends GenericMatcher {

    /**
     * The mail attribute holding the SMTP AUTH user name, if any.
     */
    private final static String SMTP_AUTH_USER_ATTRIBUTE_NAME =  
"org.apache.james.SMTPAuthUser";

    private Collection users;

    public void init() throws javax.mail.MessagingException {
        StringTokenizer st = new StringTokenizer(getCondition(), ", \t", false);
        users = new java.util.HashSet();
        String tok = null;
        while (st.hasMoreTokens()) {
            tok = st.nextToken();
            System.out.println("user from config:[" +tok + "]");
            //users.add(new MailAddress(tok));    // Remove this, it's not needed to 
have MailAddress objects here
            users.add(tok);                             // just add the (String) 
username to match getUser()'s
        }
    }

    public Collection match(Mail mail) {
        String authUser = (String) mail.getAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME);
       
        System.out.println("SMTP user for this mail:[" + ((authUser == null) ? 
"AuthUser value is null": authUser) + "]");
       
        if (authUser != null && users.contains(authUser)) {
           
                return mail.getRecipients();
        } else {
            return null;
        }
    }
}
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.502 / Virus Database: 300 - Release Date: 18/07/2003

Reply via email to