package votorola.s.line; // Copyright 2007, 2011, 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.response.line.*; import votorola.s.mail.*; import votorola.g.lang.*; import votorola.g.logging.*; import votorola.g.option.*; /** Main class of the executable vodeliver - a test tool to deliver * email messages to a mailbox. * * @see vodeliver */ 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( optionMap.get("help").hasOccured() ) { System.out.print ( "Usage: cat MESSAGE-FILE | vodeliver [maildir:/INBOX-PATH | INBOX-URL]\n" + " or cat MESSAGE-FILE | vodeliver # to voface-mail inbox\n" + "Deliver an email test message to an inbox. See also your:\n" + "http://reluk.ca/project/votorola/_/javadoc/votorola/s/mail/VOFaceMail.html#inboxStoreURLName()\n" ); System.exit( 0 ); } try { String inboxURL = null; // final after init { final int addressCount = argv.length - aFirstNonOption; if( addressCount > 1 ) { System.err.println( "vodeliver: too many arguments" ); System.err.println( GetoptX.createHelpPrompt( "vodeliver" )); System.exit( 1 ); } else if( addressCount == 1 ) inboxURL = argv[aFirstNonOption]; else { final VoteServer voteServer = new VoteServer( System.getProperty( "user.name" )); final VOFaceMail.ConstructionContext cc = VOFaceMail.ConstructionContext.configure( voteServer, VOFaceMail.compileConfigurationScript( voteServer )); inboxURL = cc.getInboxStoreURLName(); } } final Session session = Session.getDefaultInstance( new Properties() ); final Store store = session.getStore( new URLName( inboxURL )); store.connect(); try { // final Folder folder = StoreX.ensureDefaultFolder( store ); /// for Maildir, that now gives the 'cur' directory. This gives 'new': final Folder folder = store.getDefaultFolder(); folder.open( Folder.READ_WRITE ); final 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 ); } } }