package votorola.a.mail; // Copyright 2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import java.util.*; import javax.mail.*; import javax.mail.internet.*; import votorola.a.*; import votorola.a.manline.*; import votorola.g.lang.*; import votorola.g.logging.*; import votorola.g.mail.*; import votorola.g.option.*; /** Main class of the command line executable 'vodeliver' - * a test utility to deliver an email message to the inbox of the voter interface. * * @see * vodeliver(1) */ public @ThreadSafe final class VODeliver { private VODeliver() {} /** Runs the tool from the command line. * * @param argv command line argument array */ public static void main( String[] argv ) { LoggerX.i(VODeliver.class).info( "vodeliver is running with arguments " + Arrays.toString( argv )); final Map optionMap = CommandLine.compileBaseOptions(); { final int aFirstNonOption = GetoptX.parse( "vodeliver", argv, optionMap ); if( aFirstNonOption < argv.length ) { System.err.println( GetoptX.createUnexpectedArgWarning ( "vodeliver", argv[aFirstNonOption] )); System.err.println( GetoptX.createHelpPrompt( "vodeliver" )); System.exit( 1 ); } } if( optionMap.get("help").hasOccured() ) { System.out.print ( "Usage: cat MESSAGE-PATH | vodeliver\n" + " or vodeliver < MESSAGE-PATH\n" + "Deliver an email message to the inbox of the voter interface, for testing.\n" ); System.exit( 0 ); } try { final ElectoralSubserver subserver = new ElectoralSubserver( System.getProperty( "user.name" )); final MailResponder.ConfigurationContext cc = MailResponder.ConfigurationContext.configure( subserver, MailResponder.compileConfigurationScript( subserver )); final Session session = Session.getDefaultInstance( new Properties() ); final Store store = session.getStore( new URLName( cc.getInboxStoreURLName() )); store.connect(); try { final Folder folder = StoreX.ensureDefaultFolder( store ); folder.open( Folder.READ_WRITE ); MimeMessage message = new MimeMessage( session, System.in ); folder.appendMessages( new Message[]{ message }); } finally{ store.close(); } } catch( RuntimeException x ) { throw x; } catch( Exception x ) // ScriptException, MessagingException { x.printStackTrace( System.err ); System.exit( 1 ); } } }