Mercurial Hosting > luan
diff src/luan/modules/mail/MailCon.java @ 1587:fa1a9aceac3e
mail work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 12 Mar 2021 23:22:53 -0700 |
parents | fcca0ddf5a4d |
children |
line wrap: on
line diff
--- a/src/luan/modules/mail/MailCon.java Fri Mar 12 20:12:43 2021 -0700 +++ b/src/luan/modules/mail/MailCon.java Fri Mar 12 23:22:53 2021 -0700 @@ -60,20 +60,6 @@ Object body = mailParams.remove("body"); if( body == null ) throw new LuanException( "parameter 'body' is required" ); - if( body instanceof LuanTable ) { - LuanTable tbl = (LuanTable)body; - if( !tbl.isList() ) - throw new LuanException( "body table must be a list" ); - List list = tbl.asList(); - Message[] msgs = new Message[list.size()]; - for( int i=0; i<msgs.length; i++ ) { - Object obj = list.get(i); - if( !(obj instanceof LuanTable) ) - throw new LuanException( "body table must be a list of part tables" ); - msgs[i] = message((LuanTable)obj); - } - body = msgs; - } Map<String,String> headers = new LinkedHashMap<String,String>(); boolean hasContentType = false; for( Map.Entry<Object,Object> entry : mailParams.entrySet() ) { @@ -88,9 +74,29 @@ if( name.equalsIgnoreCase("content-type") ) hasContentType = true; } - if( !hasContentType && body instanceof String ) - headers.put("Content-Type","text/plain; charset=utf-8"); - return new Message(headers,body); + if( body instanceof String ) { + if( !hasContentType ) + headers.put("Content-Type","text/plain; charset=utf-8"); + return new Message(headers,(String)body); + } + if( body instanceof byte[] ) { + return new Message(headers,(byte[])body); + } + if( body instanceof LuanTable ) { + LuanTable tbl = (LuanTable)body; + if( !tbl.isList() ) + throw new LuanException( "body table must be a list" ); + List list = tbl.asList(); + Message[] msgs = new Message[list.size()]; + for( int i=0; i<msgs.length; i++ ) { + Object obj = list.get(i); + if( !(obj instanceof LuanTable) ) + throw new LuanException( "body table must be a list of part tables" ); + msgs[i] = message((LuanTable)obj); + } + return new Message(headers,msgs); + } + throw new LuanException("body must be a string, binary, or list of part tables"); } public void send(LuanTable mailTbl) throws LuanException, IOException, MailException {