Author: sebb Date: Wed Feb 17 02:22:57 2010 New Revision: 910801 URL: http://svn.apache.org/viewvc?rev=910801&view=rev Log: Basic read-only JavaMail provider implementation for reading raw mail files
Added: jakarta/jmeter/trunk/src/protocol/mail/META-INF/ jakarta/jmeter/trunk/src/protocol/mail/META-INF/javamail.providers jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java (with props) jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileMessage.java (with props) jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java (with props) Modified: jakarta/jmeter/trunk/xdocs/changes.xml Added: jakarta/jmeter/trunk/src/protocol/mail/META-INF/javamail.providers URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/META-INF/javamail.providers?rev=910801&view=auto ============================================================================== --- jakarta/jmeter/trunk/src/protocol/mail/META-INF/javamail.providers (added) +++ jakarta/jmeter/trunk/src/protocol/mail/META-INF/javamail.providers Wed Feb 17 02:22:57 2010 @@ -0,0 +1 @@ +protocol=file; type=store; class=org.apache.jmeter.protocol.mail.sampler.MailFileStore; vendor=ASF \ No newline at end of file Added: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java?rev=910801&view=auto ============================================================================== --- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java (added) +++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java Wed Feb 17 02:22:57 2010 @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.protocol.mail.sampler; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FilenameFilter; + +import javax.mail.Flags; +import javax.mail.Folder; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Store; +import javax.mail.URLName; + +import org.apache.commons.io.IOUtils; + +public class MailFileFolder extends Folder { + + private static final String FILENAME_FORMAT = "%d.msg"; + private static final String FILENAME_REGEX = "\\d+\\.msg"; + private boolean isOpen; + private final File folderPath; + private static final FilenameFilter FILENAME_FILTER = new FilenameFilter(){ + public boolean accept(File dir, String name) { + return name.matches(FILENAME_REGEX); + } + + }; + + public MailFileFolder(Store store, String path) { + super(store); + String base = store.getURLName().getHost(); // == ServerName from mail sampler + folderPath = new File(base,path); + } + + public MailFileFolder(Store store, URLName path) { + this(store, path.getFile()); + } + + @Override + public void appendMessages(Message[] messages) throws MessagingException { + throw new MessagingException("Not supported"); + } + + @Override + public void close(boolean expunge) throws MessagingException { + this.store.close(); + isOpen = false; + } + + @Override + public boolean create(int type) throws MessagingException { + return false; + } + + @Override + public boolean delete(boolean recurse) throws MessagingException { + return false; + } + + @Override + public boolean exists() throws MessagingException { + return true; + } + + @Override + public Message[] expunge() throws MessagingException { + return null; + } + + @Override + public Folder getFolder(String name) throws MessagingException { + return this; + } + + @Override + public String getFullName() { + return this.toString(); + } + + @Override + public Message getMessage(int index) throws MessagingException { + File f = new File(folderPath,String.format(FILENAME_FORMAT, Integer.valueOf(index))); + try { + FileInputStream fis = new FileInputStream(f); + try { + Message m = new MailFileMessage(this, fis, index); + return m; + } finally { + IOUtils.closeQuietly(fis); + } + } catch (FileNotFoundException e) { + throw new MessagingException("Cannot open folder: "+e.getMessage()); + } + } + + @Override + public int getMessageCount() throws MessagingException { + if (!isOpen) return -1; + File[] listFiles = folderPath.listFiles(FILENAME_FILTER); + return listFiles != null ? listFiles.length : 0; + } + + @Override + public String getName() { + return this.toString(); + } + + @Override + public Folder getParent() throws MessagingException { + return null; + } + + @Override + public Flags getPermanentFlags() { + return null; + } + + @Override + public char getSeparator() throws MessagingException { + return '/'; + } + + @Override + public int getType() throws MessagingException { + return HOLDS_MESSAGES; + } + + @Override + public boolean hasNewMessages() throws MessagingException { + return false; + } + + @Override + public boolean isOpen() { + return isOpen; + } + + @Override + public Folder[] list(String pattern) throws MessagingException { + return new Folder[]{this}; + } + + @Override + public void open(int mode) throws MessagingException { + if (mode != READ_ONLY) { + throw new MessagingException("Implementation only supports read-only access"); + } + this.mode = mode; + isOpen = true; + } + + @Override + public boolean renameTo(Folder newName) throws MessagingException { + return false; + } + +} Propchange: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileMessage.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileMessage.java?rev=910801&view=auto ============================================================================== --- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileMessage.java (added) +++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileMessage.java Wed Feb 17 02:22:57 2010 @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.protocol.mail.sampler; + +import java.io.InputStream; + +import javax.mail.Folder; +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; + +public class MailFileMessage extends MimeMessage { + + protected MailFileMessage(Folder folder, InputStream in, int number) + throws MessagingException { + super(folder, in, number); + } + +} Propchange: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileMessage.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileMessage.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java?rev=910801&view=auto ============================================================================== --- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java (added) +++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java Wed Feb 17 02:22:57 2010 @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.protocol.mail.sampler; + +import javax.mail.Folder; +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.Store; +import javax.mail.URLName; + +public class MailFileStore extends Store { + + public MailFileStore(Session s, URLName u){ + super(s,u); + } + + @Override + protected boolean protocolConnect(String host, int port, String user, String password){ + return true; + } + + @Override + public Folder getDefaultFolder() throws MessagingException { + return new MailFileFolder(this,""); + } + + @Override + public Folder getFolder(String path) throws MessagingException { + return new MailFileFolder(this, path); + } + + @Override + public Folder getFolder(URLName path) throws MessagingException { + return new MailFileFolder(this, path); + } +} Propchange: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: jakarta/jmeter/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=910801&r1=910800&r2=910801&view=diff ============================================================================== --- jakarta/jmeter/trunk/xdocs/changes.xml (original) +++ jakarta/jmeter/trunk/xdocs/changes.xml Wed Feb 17 02:22:57 2010 @@ -211,6 +211,7 @@ <li>Bug 47980 - hostname resolves to 127.0.0.1 - specifiying IP not possible</li> <li>Bug 47943 - DisabledComponentRemover is not used in Start class</li> <li>HeapDumper class for runtime generation of dumps</li> +<li>Basic read-only JavaMail provider implementation for reading raw mail files</li> </ul> <h2>Non-functional changes</h2> --------------------------------------------------------------------- To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org