Mercurial Hosting > luan
comparison mail/src/luan/modules/mail/SmtpCon.java @ 273:073044e3ac03
fix mmake.sh and multipart mail
git-svn-id: https://luan-java.googlecode.com/svn/trunk@274 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 31 Oct 2014 18:44:11 +0000 |
parents | b2c20fdcf42a |
children | ae7ae2755b48 |
comparison
equal
deleted
inserted
replaced
272:eb27e765affb | 273:073044e3ac03 |
---|---|
1 package luan.modules.mail; | 1 package luan.modules.mail; |
2 | 2 |
3 import java.util.Map; | 3 import java.util.Map; |
4 import java.util.HashMap; | |
4 import java.util.Properties; | 5 import java.util.Properties; |
5 import javax.mail.Authenticator; | 6 import javax.mail.Authenticator; |
6 import javax.mail.PasswordAuthentication; | 7 import javax.mail.PasswordAuthentication; |
7 import javax.mail.Session; | 8 import javax.mail.Session; |
8 import javax.mail.Transport; | 9 import javax.mail.Transport; |
103 Object body = mailTbl.get("body"); | 104 Object body = mailTbl.get("body"); |
104 if( body != null ) { | 105 if( body != null ) { |
105 if( body instanceof String ) { | 106 if( body instanceof String ) { |
106 msg.setText((String)body); | 107 msg.setText((String)body); |
107 } else if( body instanceof LuanTable ) { | 108 } else if( body instanceof LuanTable ) { |
109 LuanTable bodyTbl = (LuanTable)body; | |
110 Map<Object,Object> map = new HashMap<Object,Object>(bodyTbl.asMap()); | |
108 MimeMultipart mp = new MimeMultipart("alternative"); | 111 MimeMultipart mp = new MimeMultipart("alternative"); |
109 for( Map.Entry<Object,Object> entry : (LuanTable)body ) { | 112 String text = (String)map.remove("text"); |
110 String key = (String)entry.getKey(); | 113 if( text != null ) { |
111 String val = (String)entry.getValue(); | |
112 MimeBodyPart part = new MimeBodyPart(); | 114 MimeBodyPart part = new MimeBodyPart(); |
113 if( key.equals("text") ) { | 115 part.setText(text); |
114 part.setText(val); | |
115 } else if( key.equals("html") ) { | |
116 part.setContent(val,"text/html"); | |
117 } else | |
118 throw luan.exception( "invalid body type: " + key ); | |
119 mp.addBodyPart(part); | 116 mp.addBodyPart(part); |
120 } | 117 } |
118 String html = (String)map.remove("html"); | |
119 if( html != null ) { | |
120 MimeBodyPart part = new MimeBodyPart(); | |
121 part.setContent(html,"text/html"); | |
122 mp.addBodyPart(part); | |
123 } | |
124 if( !map.isEmpty() ) | |
125 throw luan.exception( "invalid body types: " + map ); | |
121 msg.setContent(mp); | 126 msg.setContent(mp); |
122 } else | 127 } else |
123 throw luan.exception( "parameter 'body' is must be a string or table" ); | 128 throw luan.exception( "parameter 'body' is must be a string or table" ); |
124 } | 129 } |
125 | 130 |