Mercurial Hosting > luan
comparison mail/src/luan/modules/mail/SmtpCon.java @ 572:f1601a4ce1aa
fix stack when calling meta-methods
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 12 Jul 2015 21:34:23 -0600 |
parents | d9df6d6cb927 |
children | 7c3ad6db8ac3 |
comparison
equal
deleted
inserted
replaced
571:cd944b010f25 | 572:f1601a4ce1aa |
---|---|
23 | 23 |
24 public final class SmtpCon { | 24 public final class SmtpCon { |
25 private final Session session; | 25 private final Session session; |
26 | 26 |
27 public SmtpCon(LuanState luan,LuanTable paramsTbl) throws LuanException { | 27 public SmtpCon(LuanState luan,LuanTable paramsTbl) throws LuanException { |
28 Map<Object,Object> params = new HashMap<Object,Object>(paramsTbl.asMap(luan)); | 28 Map<Object,Object> params = new HashMap<Object,Object>(paramsTbl.asMap(luan.JAVA)); |
29 Properties props = new Properties(System.getProperties()); | 29 Properties props = new Properties(System.getProperties()); |
30 | 30 |
31 String host = getString(luan,params,"host"); | 31 String host = getString(luan,params,"host"); |
32 if( host==null ) | 32 if( host==null ) |
33 throw luan.exception( "parameter 'host' is required" ); | 33 throw luan.exception( "parameter 'host' is required" ); |
79 } | 79 } |
80 | 80 |
81 | 81 |
82 public void send(LuanState luan,LuanTable mailTbl) throws LuanException { | 82 public void send(LuanState luan,LuanTable mailTbl) throws LuanException { |
83 try { | 83 try { |
84 Map<Object,Object> mailParams = new HashMap<Object,Object>(mailTbl.asMap(luan)); | 84 Map<Object,Object> mailParams = new HashMap<Object,Object>(mailTbl.asMap(luan.JAVA)); |
85 MimeMessage msg = new MimeMessage(session); | 85 MimeMessage msg = new MimeMessage(session); |
86 | 86 |
87 String from = getString(luan,mailParams,"from"); | 87 String from = getString(luan,mailParams,"from"); |
88 if( from != null ) | 88 if( from != null ) |
89 msg.setFrom(from); | 89 msg.setFrom(from); |
107 if( body != null ) { | 107 if( body != null ) { |
108 if( body instanceof String ) { | 108 if( body instanceof String ) { |
109 bodyPart.setText((String)body); | 109 bodyPart.setText((String)body); |
110 } else if( body instanceof LuanTable ) { | 110 } else if( body instanceof LuanTable ) { |
111 LuanTable bodyTbl = (LuanTable)body; | 111 LuanTable bodyTbl = (LuanTable)body; |
112 Map<Object,Object> map = new HashMap<Object,Object>(bodyTbl.asMap(luan)); | 112 Map<Object,Object> map = new HashMap<Object,Object>(bodyTbl.asMap(luan.JAVA)); |
113 MimeMultipart mp = new MimeMultipart("alternative"); | 113 MimeMultipart mp = new MimeMultipart("alternative"); |
114 String text = (String)map.remove("text"); | 114 String text = (String)map.remove("text"); |
115 if( text != null ) { | 115 if( text != null ) { |
116 MimeBodyPart part = new MimeBodyPart(); | 116 MimeBodyPart part = new MimeBodyPart(); |
117 part.setText(text); | 117 part.setText(text); |
140 if( body != null ) | 140 if( body != null ) |
141 mp.addBodyPart((MimeBodyPart)bodyPart); | 141 mp.addBodyPart((MimeBodyPart)bodyPart); |
142 for( Object attachment : attachmentsTbl.asList() ) { | 142 for( Object attachment : attachmentsTbl.asList() ) { |
143 if( !(attachment instanceof LuanTable) ) | 143 if( !(attachment instanceof LuanTable) ) |
144 throw luan.exception( "each attachment must be a table" ); | 144 throw luan.exception( "each attachment must be a table" ); |
145 Map<Object,Object> attachmentMap = new HashMap<Object,Object>(((LuanTable)attachment).asMap(luan)); | 145 Map<Object,Object> attachmentMap = new HashMap<Object,Object>(((LuanTable)attachment).asMap(luan.JAVA)); |
146 Object obj; | 146 Object obj; |
147 | 147 |
148 obj = attachmentMap.remove("filename"); | 148 obj = attachmentMap.remove("filename"); |
149 if( obj==null ) | 149 if( obj==null ) |
150 throw luan.exception( "an attachment is missing 'filename'" ); | 150 throw luan.exception( "an attachment is missing 'filename'" ); |