- Timestamp:
- 03/27/13 18:00:31 (12 years ago)
- Location:
- trunk/FACT++
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r15158 r15172 775 775 return ThrowException(String::New("Mail must be called as constructor")); 776 776 777 if (args.Length()!=1 || !args[0]->IsString()) 778 return ThrowException(String::New("Constructor must be called with a single string as argument")); 779 777 780 HandleScope handle_scope; 778 781 782 Handle<Array> rec = Array::New(); 783 Handle<Array> att = Array::New(); 784 Handle<Array> bcc = Array::New(); 785 Handle<Array> cc = Array::New(); 786 Handle<Array> txt = Array::New(); 787 if (rec.IsEmpty() || att.IsEmpty() || bcc.IsEmpty() || cc.IsEmpty() || txt.IsEmpty()) 788 return Undefined(); 789 779 790 Handle<Object> self = args.This(); 791 792 self->Set(String::New("subject"), args[0]->ToString(), ReadOnly); 793 self->Set(String::New("recipients"), rec, ReadOnly); 794 self->Set(String::New("attachments"), att, ReadOnly); 795 self->Set(String::New("bcc"), bcc, ReadOnly); 796 self->Set(String::New("cc"), cc, ReadOnly); 797 self->Set(String::New("text"), txt, ReadOnly); 798 780 799 self->Set(String::New("send"), FunctionTemplate::New(WrapSendMail)->GetFunction(), ReadOnly); 800 781 801 return handle_scope.Close(self); 782 802 } 783 803 784 vector<string> InterpreterV8::ValueToArray(const Handle<Value> &val )804 vector<string> InterpreterV8::ValueToArray(const Handle<Value> &val, bool only) 785 805 { 786 806 vector<string> rc; 787 if (val->IsString()) 788 { 789 rc.push_back(*String::AsciiValue(val->ToString())); 790 return rc; 791 } 792 793 if (val->IsArray()) 794 { 795 Handle<Array> arr = Handle<Array>::Cast(val); 796 for (uint32_t i=0; i<arr->Length(); i++) 797 { 798 Handle<Value> obj = arr->Get(i); 799 if (obj.IsEmpty()) 800 continue; 801 802 if (!obj->IsString()) 803 return vector<string>(); 804 805 rc.push_back(*String::AsciiValue(obj->ToString())); 806 } 807 808 Handle<Array> arr = Handle<Array>::Cast(val); 809 for (uint32_t i=0; i<arr->Length(); i++) 810 { 811 Handle<Value> obj = arr->Get(i); 812 if (obj.IsEmpty()) 813 continue; 814 815 if (obj->IsNull() || obj->IsUndefined()) 816 continue; 817 818 if (only && !obj->IsString()) 819 continue; 820 821 rc.push_back(*String::AsciiValue(obj->ToString())); 807 822 } 808 823 … … 823 838 824 839 const Handle<Value> sub = args.This()->Get(String::New("subject")); 825 const Handle<Value> rec = args.This()->Get(String::New("recipient "));840 const Handle<Value> rec = args.This()->Get(String::New("recipients")); 826 841 const Handle<Value> txt = args.This()->Get(String::New("text")); 827 const Handle<Value> att = args.This()->Get(String::New("attachment "));842 const Handle<Value> att = args.This()->Get(String::New("attachments")); 828 843 const Handle<Value> bcc = args.This()->Get(String::New("bcc")); 829 844 const Handle<Value> cc = args.This()->Get(String::New("cc")); 830 845 831 if (sub->IsUndefined())832 return ThrowException(String::New("Required property 'subject' missing."));833 834 846 const vector<string> vrec = ValueToArray(rec); 835 const vector<string> vtxt = ValueToArray(txt );847 const vector<string> vtxt = ValueToArray(txt, false); 836 848 const vector<string> vatt = ValueToArray(att); 837 849 const vector<string> vbcc = ValueToArray(bcc); … … 839 851 840 852 if (vrec.size()==0) 841 return ThrowException(String::New(" Required property 'recipient' must be a string or an array of strings."));853 return ThrowException(String::New("At least one valid string is required in 'recipients'.")); 842 854 if (vtxt.size()==0) 843 return ThrowException(String::New("Required property 'text' must be a string or an array of strings.")); 844 if (vatt.size()==0 && !att->IsUndefined()) 845 return ThrowException(String::New("Property 'attachment' must be a string or an array of strings.")); 846 if (vbcc.size()==0 && !bcc->IsUndefined()) 847 return ThrowException(String::New("Property 'bcc' must be a string or an array of strings.")); 848 if (vcc.size()==0 && !cc->IsUndefined()) 849 return ThrowException(String::New("Property 'cc' must be a string or an array of strings.")); 850 851 if (!sub->IsString()) 852 return ThrowException(String::New("Property 'subject' must be a string.")); 855 return ThrowException(String::New("At least one valid string is required in 'text'.")); 853 856 854 857 const string subject = *String::AsciiValue(sub->ToString()); 855 856 858 857 859 FILE *pipe = popen(("from=no-reply@fact-project.org mailx -~ "+vrec[0]).c_str(), "w"); … … 2389 2391 fTemplateDescription = desc; 2390 2392 2391 #ifdef HAVE_MAIL 2393 #ifdef HAVE_MAILX 2392 2394 Handle<FunctionTemplate> mail = FunctionTemplate::New(ConstructorMail); 2393 2395 mail->SetClassName(String::New("Mail")); -
trunk/FACT++/src/InterpreterV8.h
r15156 r15172 64 64 void Thread(int &id, v8::Persistent<v8::Function> func, uint32_t ms); 65 65 66 std::vector<std::string> ValueToArray(const v8::Handle<v8::Value> &val );66 std::vector<std::string> ValueToArray(const v8::Handle<v8::Value> &val, bool only=true); 67 67 68 68 v8::Handle<v8::Value> FuncWait(const v8::Arguments& args);
Note:
See TracChangeset
for help on using the changeset viewer.