pony-express 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -1
- data/VERSION +1 -1
- data/ext/mimetic.cxx +87 -0
- data/lib/pony-express.rb +1 -1
- metadata +3 -2
data/README
CHANGED
@@ -19,7 +19,7 @@ USAGE:
|
|
19
19
|
>> args = { from: "jim@example.com", to: "ralph@example.com", subject: "test email", via: "sendmail" }
|
20
20
|
>> args[:text] = "Hello!"
|
21
21
|
>> args[:html] = "<strong>Hello!</strong>"
|
22
|
-
>> PonyExpress.
|
22
|
+
>> PonyExpress.mail(args)
|
23
23
|
|
24
24
|
|
25
25
|
TODO:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/ext/mimetic.cxx
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <ruby/encoding.h>
|
3
|
+
#include <iostream>
|
4
|
+
#include <unistd.h>
|
5
|
+
#include <sstream>
|
6
|
+
#include <exception>
|
7
|
+
#include <mimetic/mimetic.h>
|
8
|
+
|
9
|
+
#define ID_CONST_GET rb_intern("const_get")
|
10
|
+
#define CONST_GET(scope, constant) (rb_funcall(scope, ID_CONST_GET, 1, rb_str_new2(constant)))
|
11
|
+
|
12
|
+
static VALUE rb_mMimetic;
|
13
|
+
static VALUE eRuntimeError;
|
14
|
+
static VALUE eArgumentError;
|
15
|
+
|
16
|
+
using namespace std;
|
17
|
+
using namespace mimetic;
|
18
|
+
|
19
|
+
#define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
|
20
|
+
|
21
|
+
VALUE rb_mimetic_build(VALUE self, VALUE options) {
|
22
|
+
ostringstream output;
|
23
|
+
|
24
|
+
VALUE text = rb_hash_aref(options, ID2SYM(rb_intern("text")));
|
25
|
+
VALUE html = rb_hash_aref(options, ID2SYM(rb_intern("html")));
|
26
|
+
VALUE to = rb_hash_aref(options, ID2SYM(rb_intern("to")));
|
27
|
+
VALUE from = rb_hash_aref(options, ID2SYM(rb_intern("from")));
|
28
|
+
VALUE subject = rb_hash_aref(options, ID2SYM(rb_intern("subject")));
|
29
|
+
|
30
|
+
if (text == Qnil) rb_raise(eArgumentError, "Mimetic.build called without :text");
|
31
|
+
if (from == Qnil) rb_raise(eArgumentError, "Mimetic.build called without :from");
|
32
|
+
if (to == Qnil) rb_raise(eArgumentError, "Mimetic.build called without :to");
|
33
|
+
if (subject == Qnil) rb_raise(eArgumentError, "Mimetic.build called without :subject");
|
34
|
+
|
35
|
+
VALUE errors = Qnil;
|
36
|
+
MimeEntity *message = NULL;
|
37
|
+
MimeEntity *html_part = NULL;
|
38
|
+
MimeEntity *text_part = NULL;
|
39
|
+
|
40
|
+
try {
|
41
|
+
message = new MimeEntity;
|
42
|
+
if (html != Qnil && text != Qnil) {
|
43
|
+
delete message;
|
44
|
+
message = new MultipartAlternative;
|
45
|
+
html_part = new MimeEntity;
|
46
|
+
text_part = new MimeEntity;
|
47
|
+
message->body().parts().push_back(text_part);
|
48
|
+
message->body().parts().push_back(html_part);
|
49
|
+
text_part->header().contentType("text/plain; charset=utf-8");
|
50
|
+
text_part->body().assign(RSTRING_PTR(text));
|
51
|
+
html_part->header().contentType("text/html; charset=utf-8");
|
52
|
+
html_part->body().assign(RSTRING_PTR(html));
|
53
|
+
}
|
54
|
+
else {
|
55
|
+
message->body().assign(RSTRING_PTR(text));
|
56
|
+
message->header().contentType("text/plain; charset=utf-8");
|
57
|
+
}
|
58
|
+
|
59
|
+
message->header().from(RSTRING_PTR(from));
|
60
|
+
message->header().to(RSTRING_PTR(to));
|
61
|
+
message->header().subject(RSTRING_PTR(subject));
|
62
|
+
|
63
|
+
output << *message << endl;
|
64
|
+
delete message;
|
65
|
+
return rb_str_new2(output.str().c_str());
|
66
|
+
}
|
67
|
+
catch(exception &e) {
|
68
|
+
if (message != NULL) delete message;
|
69
|
+
errors = rb_str_new2(e.what());
|
70
|
+
}
|
71
|
+
catch (...) {
|
72
|
+
if (message != NULL) delete message;
|
73
|
+
errors = rb_str_new2("Unknown Error");
|
74
|
+
}
|
75
|
+
|
76
|
+
rb_raise(eRuntimeError, "Mimetic boo boo : %s\n", RSTRING_PTR(errors));
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
extern "C" {
|
81
|
+
void Init_mimetic(void) {
|
82
|
+
eRuntimeError = CONST_GET(rb_mKernel, "RuntimeError");
|
83
|
+
eArgumentError = CONST_GET(rb_mKernel, "ArgumentError");
|
84
|
+
rb_mMimetic = rb_define_module("Mimetic");
|
85
|
+
rb_define_module_function(rb_mMimetic, "build", VALUEFUNC(rb_mimetic_build), 1);
|
86
|
+
}
|
87
|
+
}
|
data/lib/pony-express.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pony-express
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bharanee Rathna
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-06-
|
12
|
+
date: 2010-06-02 00:00:00 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -25,6 +25,7 @@ extra_rdoc_files:
|
|
25
25
|
files:
|
26
26
|
- README
|
27
27
|
- VERSION
|
28
|
+
- ext/mimetic.cxx
|
28
29
|
- lib/pony-express.rb
|
29
30
|
- LICENSE
|
30
31
|
has_rdoc: true
|