diff mail/src/luan/modules/mail/SmtpCon.java @ 578:60c549d43988

remove LuanState.exception()
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 14 Jul 2015 17:40:48 -0600
parents 7c3ad6db8ac3
children cdc70de628b5
line wrap: on
line diff
--- a/mail/src/luan/modules/mail/SmtpCon.java	Mon Jul 13 20:53:02 2015 -0600
+++ b/mail/src/luan/modules/mail/SmtpCon.java	Tue Jul 14 17:40:48 2015 -0600
@@ -30,7 +30,7 @@
 
 		String host = getString(luan,params,"host");
 		if( host==null )
-			throw luan.exception( "parameter 'host' is required" );
+			throw new LuanException(luan, "parameter 'host' is required" );
 		props.setProperty("mail.smtp.host",host);
 
 		Object port = params.remove("port");
@@ -41,10 +41,10 @@
 			} else if( port instanceof Number ) {
 				Integer i = Luan.asInteger(port);
 				if( i == null )
-					throw luan.exception( "parameter 'port' must be an integer" );
+					throw new LuanException(luan, "parameter 'port' must be an integer" );
 				s = i.toString();
 			} else {
-				throw luan.exception( "parameter 'port' must be an integer" );
+				throw new LuanException(luan, "parameter 'port' must be an integer" );
 			}
 			props.setProperty("mail.smtp.socketFactory.port", s);
 			props.setProperty("mail.smtp.port", s);
@@ -56,7 +56,7 @@
 		} else {
 			String password = getString(luan,params,"password");
 			if( password==null )
-				throw luan.exception( "parameter 'password' is required with 'username'" );
+				throw new LuanException(luan, "parameter 'password' is required with 'username'" );
 			props.setProperty("mail.smtp.auth","true");
 			final PasswordAuthentication pa = new PasswordAuthentication(username,password);
 			Authenticator auth = new Authenticator() {
@@ -68,13 +68,13 @@
 		}
 
 		if( !params.isEmpty() )
-			throw luan.exception( "unrecognized parameters: "+params );
+			throw new LuanException(luan, "unrecognized parameters: "+params );
 	}
 
 	private String getString(LuanState luan,Map<Object,Object> params,String key) throws LuanException {
 		Object val = params.remove(key);
 		if( val!=null && !(val instanceof String) )
-			throw luan.exception( "parameter '"+key+"' must be a string" );
+			throw new LuanException(luan, "parameter '"+key+"' must be a string" );
 		return (String)val;
 	}
 
@@ -124,49 +124,49 @@
 						mp.addBodyPart(part);
 					}
 					if( !map.isEmpty() )
-						throw luan.exception( "invalid body types: " + map );
+						throw new LuanException(luan, "invalid body types: " + map );
 					bodyPart.setContent(mp);
 				} else
-					throw luan.exception( "parameter 'body' must be a string or table" );
+					throw new LuanException(luan, "parameter 'body' must be a string or table" );
 			}
 
 			if( attachments != null ) {
 				if( !(attachments instanceof LuanTable) )
-					throw luan.exception( "parameter 'attachments' must be a table" );
+					throw new LuanException(luan, "parameter 'attachments' must be a table" );
 				LuanTable attachmentsTbl = (LuanTable)attachments;
 				if( !attachmentsTbl.isList() )
-					throw luan.exception( "parameter 'attachments' must be a list" );
+					throw new LuanException(luan, "parameter 'attachments' must be a list" );
 				MimeMultipart mp = new MimeMultipart("mixed");
 				if( body != null )
 					mp.addBodyPart((MimeBodyPart)bodyPart);
 				for( Object attachment : attachmentsTbl.asList() ) {
 					if( !(attachment instanceof LuanTable) )
-						throw luan.exception( "each attachment must be a table" );
+						throw new LuanException(luan, "each attachment must be a table" );
 					Map<Object,Object> attachmentMap = new HashMap<Object,Object>(((LuanTable)attachment).asMap(luan));
 					Object obj;
 
 					obj = attachmentMap.remove("filename");
 					if( obj==null )
-						throw luan.exception( "an attachment is missing 'filename'" );
+						throw new LuanException(luan, "an attachment is missing 'filename'" );
 					if( !(obj instanceof String) )
-						throw luan.exception( "an attachment filename must be a string" );
+						throw new LuanException(luan, "an attachment filename must be a string" );
 					String filename = (String)obj;
 
 					obj = attachmentMap.remove("content_type");
 					if( obj==null )
-						throw luan.exception( "an attachment is missing 'content_type'" );
+						throw new LuanException(luan, "an attachment is missing 'content_type'" );
 					if( !(obj instanceof String) )
-						throw luan.exception( "an attachment content_type must be a string" );
+						throw new LuanException(luan, "an attachment content_type must be a string" );
 					String content_type = (String)obj;
 
 					Object content = attachmentMap.remove("content");
 					if( content==null )
-						throw luan.exception( "an attachment is missing 'content'" );
+						throw new LuanException(luan, "an attachment is missing 'content'" );
 					if( content_type.startsWith("text/") && content instanceof byte[] )
 						content = new String((byte[])content);
 
 					if( !attachmentMap.isEmpty() )
-						throw luan.exception( "unrecognized attachment parameters: "+attachmentMap );
+						throw new LuanException(luan, "unrecognized attachment parameters: "+attachmentMap );
 
 					MimeBodyPart part = new MimeBodyPart();
 					part.setContent(content,content_type);
@@ -177,11 +177,11 @@
 			}
 
 			if( !mailParams.isEmpty() )
-				throw luan.exception( "unrecognized parameters: "+mailParams );
+				throw new LuanException(luan, "unrecognized parameters: "+mailParams );
 
 			Transport.send(msg);
 		} catch(MessagingException e) {
-			throw luan.exception(e);
+			throw new LuanException(luan,e);
 		}
 	}