milter 2.0.0 → 3.0.0
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.
- package/LICENSE +21 -0
- package/README.md +593 -121
- package/dist/constants.cjs +105 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +63 -0
- package/dist/constants.d.ts +63 -0
- package/dist/constants.js +73 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.cjs +976 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +187 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +914 -0
- package/dist/index.js.map +1 -0
- package/package.json +116 -22
- package/res/maail-logo.svg +11 -0
- package/res/milterjs-logo.svg +79 -0
- package/.npmignore +0 -7
- package/binding.gyp +0 -13
- package/lib/milter.js +0 -1
- package/src/envelope.cc +0 -602
- package/src/envelope.h +0 -94
- package/src/events.cc +0 -429
- package/src/events.h +0 -303
- package/src/forward.h +0 -10
- package/src/milter.cc +0 -732
- package/src/milter.h +0 -76
package/src/envelope.cc
DELETED
|
@@ -1,602 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
#include <stdlib.h>
|
|
5
|
-
#include <assert.h>
|
|
6
|
-
#include <node.h>
|
|
7
|
-
#include <v8.h>
|
|
8
|
-
#include "envelope.h"
|
|
9
|
-
|
|
10
|
-
using namespace v8;
|
|
11
|
-
using namespace node;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Persistent<Function> Envelope::constructor;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
*/
|
|
19
|
-
Envelope::Envelope ()
|
|
20
|
-
{ }
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*/
|
|
24
|
-
Envelope::~Envelope ()
|
|
25
|
-
{ }
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
*/
|
|
30
|
-
void Envelope::Init (Local<Object> exports)
|
|
31
|
-
{
|
|
32
|
-
Isolate *isolate = exports->GetIsolate();
|
|
33
|
-
Local<FunctionTemplate> tmpl = FunctionTemplate::New(isolate, New);
|
|
34
|
-
tmpl->SetClassName(String::NewFromUtf8(isolate, "Envelope"));
|
|
35
|
-
tmpl->InstanceTemplate()->SetInternalFieldCount(2);
|
|
36
|
-
|
|
37
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "done", Done);
|
|
38
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "negotiate", Negotiate);
|
|
39
|
-
|
|
40
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "getsymval", SMFI_GetSymbol);
|
|
41
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "setsymlist", SMFI_SetSymbolList);
|
|
42
|
-
|
|
43
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "setreply", SMFI_SetReply);
|
|
44
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "setmlreply", SMFI_SetMultilineReply);
|
|
45
|
-
|
|
46
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "progress", SMFI_Progress);
|
|
47
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "quarantine", SMFI_Quarantine);
|
|
48
|
-
|
|
49
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "addheader", SMFI_AddHeader);
|
|
50
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "chgheader", SMFI_ChangeHeader);
|
|
51
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "insheader", SMFI_InsertHeader);
|
|
52
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "replacebody", SMFI_ReplaceBody);
|
|
53
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "addrcpt", SMFI_AddRecipient);
|
|
54
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "addrcpt_par", SMFI_AddRecipientExtended);
|
|
55
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "delrcpt", SMFI_DelRecipient);
|
|
56
|
-
NODE_SET_PROTOTYPE_METHOD(tmpl, "chgfrom", SMFI_ChangeFrom);
|
|
57
|
-
|
|
58
|
-
constructor.Reset(isolate, tmpl->GetFunction());
|
|
59
|
-
// XXX: uncomment to let the programmer use 'new Envelope()'?
|
|
60
|
-
//exports->Set(String::NewFromUtf8(Isolate, "Envelope"), tmpl->GetFunction());
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*/
|
|
66
|
-
void Envelope::NewInstance (const FunctionCallbackInfo<Value> &args)
|
|
67
|
-
{
|
|
68
|
-
Isolate *isolate = args.GetIsolate();
|
|
69
|
-
Local<Value> argv[0] = { };
|
|
70
|
-
Local<Function> cons = Local<Function>::New(isolate, constructor);
|
|
71
|
-
Local<Context> context = isolate->GetCurrentContext();
|
|
72
|
-
Local<Object> envelope = cons->NewInstance(context, 0, argv).ToLocalChecked();
|
|
73
|
-
args.GetReturnValue().Set(envelope);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
*/
|
|
79
|
-
Local<Object> Envelope::PrivateInstance (Isolate *isolate)
|
|
80
|
-
{
|
|
81
|
-
Local<Value> argv[0] = { };
|
|
82
|
-
Local<Function> cons = Local<Function>::New(isolate, constructor);
|
|
83
|
-
Local<Context> context = isolate->GetCurrentContext();
|
|
84
|
-
Local<Object> envelope = cons->NewInstance(context, 0, argv).ToLocalChecked();
|
|
85
|
-
envelope->Set(String::NewFromUtf8(isolate, "local", String::kInternalizedString), Object::New(isolate));
|
|
86
|
-
return envelope;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
*/
|
|
92
|
-
void Envelope::New (const FunctionCallbackInfo<Value> &args)
|
|
93
|
-
{
|
|
94
|
-
Isolate *isolate = args.GetIsolate();
|
|
95
|
-
|
|
96
|
-
if (args.IsConstructCall())
|
|
97
|
-
{
|
|
98
|
-
Envelope *envelope = new Envelope;
|
|
99
|
-
envelope->Wrap(args.This());
|
|
100
|
-
args.GetReturnValue().Set(args.This());
|
|
101
|
-
}
|
|
102
|
-
else
|
|
103
|
-
{
|
|
104
|
-
const unsigned int argc = 0;
|
|
105
|
-
Local<Value> argv[argc] = { };
|
|
106
|
-
Local<Function> cons = Local<Function>::New(isolate, constructor);
|
|
107
|
-
Local<Context> context = isolate->GetCurrentContext();
|
|
108
|
-
args.GetReturnValue().Set(cons->NewInstance(context, argc, argv).ToLocalChecked());
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
*/
|
|
115
|
-
void Envelope::SetCurrentEvent (MilterEvent *event)
|
|
116
|
-
{
|
|
117
|
-
assert (event != NULL);
|
|
118
|
-
this->current_event = event;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
*/
|
|
123
|
-
void Envelope::SetMilterContext (SMFICTX *context)
|
|
124
|
-
{
|
|
125
|
-
assert (context != NULL);
|
|
126
|
-
this->smfi_context = context;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
*/
|
|
133
|
-
void Envelope::Done (const FunctionCallbackInfo<Value> &args)
|
|
134
|
-
{
|
|
135
|
-
Isolate *isolate = args.GetIsolate();
|
|
136
|
-
Envelope *envelope = ObjectWrap::Unwrap<Envelope>(args.Holder());
|
|
137
|
-
#ifdef DEBUG_COMMANDS
|
|
138
|
-
fprintf(stderr, "Envelope::Done started\n");
|
|
139
|
-
#endif
|
|
140
|
-
if (NULL == envelope)
|
|
141
|
-
{
|
|
142
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Done unwrap failed")));
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
MilterEvent *event = envelope->current_event;
|
|
146
|
-
if (NULL == event)
|
|
147
|
-
{
|
|
148
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope done method called outside event context")));
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (args.Length() < 1)
|
|
153
|
-
{
|
|
154
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (!args[0]->IsNumber())
|
|
159
|
-
{
|
|
160
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "First argument: expected number")));
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
event->Done(isolate, args[0]->IntegerValue());
|
|
165
|
-
#ifdef DEBUG_COMMANDS
|
|
166
|
-
fprintf(stderr, "Envelope::Done completed\n");
|
|
167
|
-
#endif
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
*/
|
|
173
|
-
void Envelope::Negotiate (const FunctionCallbackInfo<Value> &args)
|
|
174
|
-
{
|
|
175
|
-
Isolate *isolate = args.GetIsolate();
|
|
176
|
-
Envelope *envelope = ObjectWrap::Unwrap<Envelope>(args.Holder());
|
|
177
|
-
|
|
178
|
-
if (NULL == envelope)
|
|
179
|
-
{
|
|
180
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Negotiate unwrap failed")));
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
MilterEvent *event = envelope->current_event;
|
|
184
|
-
|
|
185
|
-
if (NULL == event || !event->IsNegotiate())
|
|
186
|
-
{
|
|
187
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope negotiate method called outside event context")));
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (args.Length() < 4)
|
|
193
|
-
{
|
|
194
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
for (int i = 0; i < 4; i++)
|
|
199
|
-
if (!args[i]->IsNumber())
|
|
200
|
-
{
|
|
201
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Invalid argument: expected number")));
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
unsigned long f0 = args[0]->Uint32Value();
|
|
206
|
-
unsigned long f1 = args[1]->Uint32Value();
|
|
207
|
-
unsigned long f2 = args[2]->Uint32Value();
|
|
208
|
-
unsigned long f3 = args[3]->Uint32Value();
|
|
209
|
-
|
|
210
|
-
MilterNegotiate *ev = (MilterNegotiate *)event;
|
|
211
|
-
ev->Negotiate(f0, f1, f2, f3);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
*/
|
|
217
|
-
void Envelope::SMFI_GetSymbol (const FunctionCallbackInfo<Value> &args)
|
|
218
|
-
{
|
|
219
|
-
Isolate *isolate = args.GetIsolate();
|
|
220
|
-
Envelope *envelope = ObjectWrap::Unwrap<Envelope>(args.Holder());
|
|
221
|
-
|
|
222
|
-
if (NULL == envelope)
|
|
223
|
-
{
|
|
224
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "SMFI_GetSymbol unwrap failed")));
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
Local<String> symname = args[0]->ToString();
|
|
229
|
-
char *c_symname = new char[symname->Utf8Length()+1];
|
|
230
|
-
symname->WriteUtf8(c_symname);
|
|
231
|
-
|
|
232
|
-
char *c_symval = smfi_getsymval(envelope->smfi_context, c_symname);
|
|
233
|
-
delete [] c_symname;
|
|
234
|
-
|
|
235
|
-
args.GetReturnValue().Set(String::NewFromUtf8(isolate, c_symval ? c_symval : ""));
|
|
236
|
-
|
|
237
|
-
// TODO: either segfault or memory leak here, probably
|
|
238
|
-
if (c_symval)
|
|
239
|
-
free(c_symval);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
*/
|
|
245
|
-
void Envelope::SMFI_SetSymbolList (const FunctionCallbackInfo<Value> &args)
|
|
246
|
-
{
|
|
247
|
-
Isolate *isolate = args.GetIsolate();
|
|
248
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Not yet implemented")));
|
|
249
|
-
|
|
250
|
-
// TODO: smfi_setsymlist
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
*/
|
|
256
|
-
void Envelope::SMFI_SetReply (const FunctionCallbackInfo<Value> &args)
|
|
257
|
-
{
|
|
258
|
-
Isolate *isolate = args.GetIsolate();
|
|
259
|
-
Envelope *envelope = ObjectWrap::Unwrap<Envelope>(args.Holder());
|
|
260
|
-
|
|
261
|
-
if (NULL == envelope)
|
|
262
|
-
{
|
|
263
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "SMFI_SetReply unwrap failed")));
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
MilterEvent *event = envelope->current_event;
|
|
267
|
-
if (NULL == event)
|
|
268
|
-
{
|
|
269
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope method called out of event context")));
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (event->IsNegotiate() /*|| event->IsConnect()*/)
|
|
273
|
-
{
|
|
274
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope method called from prohibited event context")));
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (args.Length() < 1)
|
|
280
|
-
{
|
|
281
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (!args[0]->IsString() && !args[0]->IsNumber())
|
|
286
|
-
{
|
|
287
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "First argument: expected number or string")));
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (args.Length() > 1)
|
|
292
|
-
{
|
|
293
|
-
if (!args[1]->IsString() && !args[1]->IsNull() && !args[1]->IsUndefined())
|
|
294
|
-
{
|
|
295
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Second argument: expected string, null, or undefined")));
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
if (args.Length() > 2)
|
|
299
|
-
{
|
|
300
|
-
if (!args[2]->IsString() && !args[2]->IsNull() && !args[1]->IsUndefined())
|
|
301
|
-
{
|
|
302
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Third argument: expected string, null, or undefined")));
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
Local<String> rcode = args[0]->ToString();
|
|
309
|
-
char *c_rcode = new char[rcode->Utf8Length()+1];
|
|
310
|
-
rcode->WriteUtf8(c_rcode);
|
|
311
|
-
|
|
312
|
-
char *c_xcode = NULL;
|
|
313
|
-
char *c_message = NULL;
|
|
314
|
-
|
|
315
|
-
if (args.Length() > 1 && args[1]->IsString())
|
|
316
|
-
{
|
|
317
|
-
Local<String> xcode = args[1]->ToString();
|
|
318
|
-
c_xcode = new char[xcode->Utf8Length()+1];
|
|
319
|
-
xcode->WriteUtf8(c_xcode);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (args.Length() > 2 && args[2]->IsString())
|
|
323
|
-
{
|
|
324
|
-
Local<String> message = args[2]->ToString();
|
|
325
|
-
c_message = new char[message->Utf8Length()+1];
|
|
326
|
-
message->WriteUtf8(c_message);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
int r = smfi_setreply(envelope->smfi_context, c_rcode, c_xcode, c_message);
|
|
330
|
-
|
|
331
|
-
delete [] c_rcode;
|
|
332
|
-
if (c_xcode)
|
|
333
|
-
delete [] c_xcode;
|
|
334
|
-
if (c_message)
|
|
335
|
-
delete [] c_message;
|
|
336
|
-
|
|
337
|
-
args.GetReturnValue().Set(Number::New(isolate, r));
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
*/
|
|
343
|
-
void Envelope::SMFI_SetMultilineReply (const FunctionCallbackInfo<Value> &args)
|
|
344
|
-
{
|
|
345
|
-
Isolate *isolate = args.GetIsolate();
|
|
346
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Not yet implemented")));
|
|
347
|
-
|
|
348
|
-
// TODO: implement with variable arguments somehow. smfi_setmlreply(rcode,xcode,vaargs)
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
*/
|
|
354
|
-
void Envelope::SMFI_Progress (const FunctionCallbackInfo<Value> &args)
|
|
355
|
-
{
|
|
356
|
-
Isolate *isolate = args.GetIsolate();
|
|
357
|
-
Envelope *envelope = ObjectWrap::Unwrap<Envelope>(args.Holder());
|
|
358
|
-
|
|
359
|
-
if (NULL == envelope)
|
|
360
|
-
{
|
|
361
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "SMFI_Progress unwrap failed")));
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
MilterEvent *event = envelope->current_event;
|
|
365
|
-
if (NULL == event)
|
|
366
|
-
{
|
|
367
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope method called outside event context")));
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (!event->IsEndMessage())
|
|
372
|
-
{
|
|
373
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope method called from prohibited event context")));
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
int r = smfi_progress(envelope->smfi_context);
|
|
377
|
-
args.GetReturnValue().Set(Number::New(isolate, r));
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
*/
|
|
383
|
-
void Envelope::SMFI_AddHeader (const FunctionCallbackInfo<Value> &args)
|
|
384
|
-
{
|
|
385
|
-
Isolate *isolate = args.GetIsolate();
|
|
386
|
-
Envelope *envelope = ObjectWrap::Unwrap<Envelope>(args.Holder());
|
|
387
|
-
|
|
388
|
-
if (NULL == envelope)
|
|
389
|
-
{
|
|
390
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "SMFI_AddHeader unwrap failed")));
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
MilterEvent *event = envelope->current_event;
|
|
394
|
-
if (NULL == event)
|
|
395
|
-
{
|
|
396
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope method called outside event context")));
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
if (!event->IsEndMessage())
|
|
400
|
-
{
|
|
401
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope method called from prohibited event context")));
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
if (args.Length() < 2)
|
|
406
|
-
{
|
|
407
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (!args[0]->IsString())
|
|
412
|
-
{
|
|
413
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "First argument: expected string")));
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (!args[1]->IsString())
|
|
418
|
-
{
|
|
419
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Second argument: expected string")));
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
Local<String> headerf = args[0]->ToString();
|
|
424
|
-
Local<String> headerv = args[1]->ToString();
|
|
425
|
-
char *c_name = new char[headerf->Utf8Length()+1];
|
|
426
|
-
char *c_value = new char[headerv->Utf8Length()+1];
|
|
427
|
-
|
|
428
|
-
headerf->WriteUtf8(c_name);
|
|
429
|
-
headerv->WriteUtf8(c_value);
|
|
430
|
-
|
|
431
|
-
int r = smfi_addheader(envelope->smfi_context, c_name, c_value);
|
|
432
|
-
|
|
433
|
-
delete [] c_name;
|
|
434
|
-
delete [] c_value;
|
|
435
|
-
|
|
436
|
-
args.GetReturnValue().Set(Number::New(isolate, r));
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
*/
|
|
442
|
-
void Envelope::SMFI_ChangeHeader (const FunctionCallbackInfo<Value> &args)
|
|
443
|
-
{
|
|
444
|
-
// TODO: smfi_chgheader(envelope->smfi_context, name, index, value)
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
*/
|
|
450
|
-
void Envelope::SMFI_InsertHeader (const FunctionCallbackInfo<Value> &args)
|
|
451
|
-
{
|
|
452
|
-
// TODO: smfi_insheader(envelope->smfi_context, index, name, value)
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* who would ever do this? implement later when actually needed
|
|
458
|
-
*/
|
|
459
|
-
void Envelope::SMFI_ReplaceBody (const FunctionCallbackInfo<Value> &args)
|
|
460
|
-
{
|
|
461
|
-
// TODO: smfi_replacebody
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
*/
|
|
467
|
-
void Envelope::SMFI_AddRecipient (const FunctionCallbackInfo<Value> &args)
|
|
468
|
-
{
|
|
469
|
-
// TODO: smfi_addrcpt
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
*/
|
|
475
|
-
void Envelope::SMFI_AddRecipientExtended (const FunctionCallbackInfo<Value> &args)
|
|
476
|
-
{
|
|
477
|
-
// TODO: smfi_addrcpt_par
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
*/
|
|
483
|
-
void Envelope::SMFI_DelRecipient (const FunctionCallbackInfo<Value> &args)
|
|
484
|
-
{
|
|
485
|
-
// TODO: smfi_delrcpt
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
*/
|
|
491
|
-
void Envelope::SMFI_Quarantine (const FunctionCallbackInfo<Value> &args)
|
|
492
|
-
{
|
|
493
|
-
Isolate *isolate = args.GetIsolate();
|
|
494
|
-
Envelope *envelope = ObjectWrap::Unwrap<Envelope>(args.Holder());
|
|
495
|
-
|
|
496
|
-
if (NULL == envelope)
|
|
497
|
-
{
|
|
498
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "SMFI_Quarantine unwrap failed")));
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
MilterEvent *event = envelope->current_event;
|
|
502
|
-
if (NULL == event)
|
|
503
|
-
{
|
|
504
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope method called outside event context")));
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
if (!event->IsEndMessage())
|
|
508
|
-
{
|
|
509
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Envelope method called from prohibited event context")));
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
if (args.Length() < 1)
|
|
515
|
-
{
|
|
516
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
if (!args[0]->IsString())
|
|
520
|
-
{
|
|
521
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "First argument: expected string")));
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
Local<String> reason = args[0]->ToString();
|
|
526
|
-
size_t len = reason->Utf8Length();
|
|
527
|
-
if (len < 1)
|
|
528
|
-
{
|
|
529
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "First argument: expected non-empty string")));
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
char *c_reason = new char[len+1];
|
|
534
|
-
reason->WriteUtf8(c_reason);
|
|
535
|
-
int r = smfi_quarantine(envelope->smfi_context, c_reason);
|
|
536
|
-
delete [] c_reason;
|
|
537
|
-
|
|
538
|
-
args.GetReturnValue().Set(Number::New(isolate, r));
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
*/
|
|
544
|
-
void Envelope::SMFI_ChangeFrom (const FunctionCallbackInfo<Value> &args)
|
|
545
|
-
{
|
|
546
|
-
Isolate *isolate = args.GetIsolate();
|
|
547
|
-
Envelope *envelope = ObjectWrap::Unwrap<Envelope>(args.Holder());
|
|
548
|
-
|
|
549
|
-
if (NULL == envelope)
|
|
550
|
-
{
|
|
551
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "SMFI_ChangeFrom unwrap failed")));
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
MilterEvent *event = envelope->current_event;
|
|
555
|
-
if (NULL == event)
|
|
556
|
-
{
|
|
557
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope method called outside event context")));
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
if (!event->IsEndMessage())
|
|
561
|
-
{
|
|
562
|
-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Envelope method called from prohibited event context")));
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
if (args.Length() < 1)
|
|
567
|
-
{
|
|
568
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
if (!args[0]->IsString())
|
|
573
|
-
{
|
|
574
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "First argument: expected string")));
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
if (args.Length() > 1 && !args[1]->IsString())
|
|
578
|
-
{
|
|
579
|
-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Second argument: expected string")));
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
Local<String> address = args[0]->ToString();
|
|
585
|
-
char *c_address = new char[address->Utf8Length()+1];
|
|
586
|
-
char *c_esmtp_args = NULL;
|
|
587
|
-
address->WriteUtf8(c_address);
|
|
588
|
-
if (args.Length() > 1)
|
|
589
|
-
{
|
|
590
|
-
Local<String> esmtp_args = args[1]->ToString();
|
|
591
|
-
c_esmtp_args = new char[esmtp_args->Utf8Length()+1];
|
|
592
|
-
esmtp_args->WriteUtf8(c_esmtp_args);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
int r = smfi_chgfrom(envelope->smfi_context, c_address, c_esmtp_args);
|
|
596
|
-
|
|
597
|
-
delete [] c_address;
|
|
598
|
-
if (c_esmtp_args)
|
|
599
|
-
delete [] c_esmtp_args;
|
|
600
|
-
|
|
601
|
-
args.GetReturnValue().Set(Number::New(isolate, r));
|
|
602
|
-
}
|
package/src/envelope.h
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mail session envelope
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
#ifndef MILTER_ENVELOPE_H
|
|
7
|
-
#define MILTER_ENVELOPE_H
|
|
8
|
-
|
|
9
|
-
#include <node.h>
|
|
10
|
-
#include <node_object_wrap.h>
|
|
11
|
-
#include <v8.h>
|
|
12
|
-
#include "libmilter/mfapi.h"
|
|
13
|
-
#include "events.h"
|
|
14
|
-
|
|
15
|
-
using namespace v8;
|
|
16
|
-
using namespace node;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
*/
|
|
21
|
-
class Envelope : public ObjectWrap
|
|
22
|
-
{
|
|
23
|
-
public:
|
|
24
|
-
static void Init (Local<Object> exports);
|
|
25
|
-
|
|
26
|
-
void SetCurrentEvent (MilterEvent *event);
|
|
27
|
-
void SetMilterContext (SMFICTX *context);
|
|
28
|
-
|
|
29
|
-
static Local<Object> PrivateInstance (Isolate *isolate);
|
|
30
|
-
|
|
31
|
-
private:
|
|
32
|
-
explicit Envelope ();
|
|
33
|
-
~Envelope ();
|
|
34
|
-
|
|
35
|
-
static Persistent<Function> constructor;
|
|
36
|
-
|
|
37
|
-
static void NewInstance (const FunctionCallbackInfo<Value> &args);
|
|
38
|
-
|
|
39
|
-
static void New (const FunctionCallbackInfo<Value> &args);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* the completion callback provided to each event callback, via the latter's
|
|
43
|
-
* first argument. all js funcs have the signature:
|
|
44
|
-
* function eventname (envelope, ...)
|
|
45
|
-
*
|
|
46
|
-
* and all of them continue a libmilter thread by calling
|
|
47
|
-
* envelope.done(retval);
|
|
48
|
-
*
|
|
49
|
-
* where retval is an SMFIS_* filter status code.
|
|
50
|
-
*/
|
|
51
|
-
static void Done (const FunctionCallbackInfo<Value> &args);
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* during negotiate, just before continuation, the implementor needs to let
|
|
55
|
-
* us know what to store in the pointers to config values f0-f3.
|
|
56
|
-
*/
|
|
57
|
-
static void Negotiate (const FunctionCallbackInfo<Value> &args);
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* allowed whenever.
|
|
61
|
-
*/
|
|
62
|
-
static void SMFI_GetSymbol (const FunctionCallbackInfo<Value> &args);
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* allowed during negotiate.
|
|
66
|
-
*/
|
|
67
|
-
static void SMFI_SetSymbolList (const FunctionCallbackInfo<Value> &args);
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* allowed in events other than connect (and negotiate, i suspect.)
|
|
71
|
-
*/
|
|
72
|
-
static void SMFI_SetReply (const FunctionCallbackInfo<Value> &args);
|
|
73
|
-
static void SMFI_SetMultilineReply (const FunctionCallbackInfo<Value> &args);
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* these modifiers are allowed during EOM.
|
|
77
|
-
*/
|
|
78
|
-
static void SMFI_Progress (const FunctionCallbackInfo<Value> &args);
|
|
79
|
-
static void SMFI_Quarantine (const FunctionCallbackInfo<Value> &args);
|
|
80
|
-
|
|
81
|
-
static void SMFI_AddHeader (const FunctionCallbackInfo<Value> &args);
|
|
82
|
-
static void SMFI_ChangeHeader (const FunctionCallbackInfo<Value> &args);
|
|
83
|
-
static void SMFI_InsertHeader (const FunctionCallbackInfo<Value> &args);
|
|
84
|
-
static void SMFI_ReplaceBody (const FunctionCallbackInfo<Value> &args);
|
|
85
|
-
static void SMFI_AddRecipient (const FunctionCallbackInfo<Value> &args);
|
|
86
|
-
static void SMFI_AddRecipientExtended (const FunctionCallbackInfo<Value> &args);
|
|
87
|
-
static void SMFI_DelRecipient (const FunctionCallbackInfo<Value> &args);
|
|
88
|
-
static void SMFI_ChangeFrom (const FunctionCallbackInfo<Value> &args);
|
|
89
|
-
|
|
90
|
-
MilterEvent *current_event;
|
|
91
|
-
SMFICTX *smfi_context;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
#endif
|