Dbx.xs

filter: Statementstmt 42.3% 102 / 241 Branchbran 25.0% 34 / 136 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 36.0% 136 / 377 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Mail/Transport/Dbx.pm ↑ Summary const-xs.inc »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #include "ppport.h"
6  
7 #include "libdbx/libdbx.h"
8 #include "libdbx/timeconv.h"
9  
10 #include "const-c.inc"
11  
12 /* This is not gentlemen-like:
13 * But under Win32: (PerlIO*) == (FILE*) */
14 #ifdef _WIN32
15 # define PerlIO_exportFILE(f,fl) ((FILE*)(f))
16 #endif
17  
18 #define glob_ref(sv) (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV)
19 #define sv_to_file(sv) (PerlIO_exportFILE(IoIFP(sv_2io(sv)), NULL))
20  
21 #define WARN fprintf(stderr, "%i\n", __LINE__)
22 #define WARNi(arg) fprintf(stderr, "%i: %i\n", __LINE__, arg)
23  
24 /* We're not thread-safe anyway. :-)
25 * But we cannot do without for garbage-collecting. */
26 int IN_DBX_DESTROY = 0;
27  
28 struct dbx_email {
29 SV *dbx; /* Mail::Transport::Dbx object */
30 DBXEMAIL *email;
31 char *header; /* just the header */
32 char *body; /* just the body */
33 };
34  
35 struct dbx_folder {
36 SV *dbx; /* Mail::Transport::Dbx object */
37 DBXFOLDER *folder;
38 AV *fullpath;
39 };
40  
41 struct dbx_box {
42 DBX *dbx;
43 SV **subfolders; /* Mail::Transport::Dbx::Folder objects */
44 /* originally used for fullpath() but now obsolete */
45 /* int *indexid;
46 int indexsize;
47 */
48 };
49  
50 typedef struct dbx_email DBX_EMAIL;
51 typedef struct dbx_folder DBX_FOLDER;
52 typedef struct dbx_box DBX_BOX;
53  
54 typedef struct {
55 char *name;
56 int pid;
57 } folder_info;
58  
59 /* copied from perl/pp_sys.c */
60 static char *dayname[] = {
61 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
62 };
63 static char *monname[] = {
64 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
65 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
66 };
67  
68 6 char * errstr () {
69 6 switch(dbx_errno) {
70 /* messages copied from libdbx.h */
71 4 case DBX_NOERROR:
72 4 return "No error";
73 0 case DBX_BADFILE:
74 0 return "Dbx file operation failed (open or close)";
75 0 case DBX_ITEMCOUNT:
76 0 return "Reading of Item Count from dbx file failed";
77 0 case DBX_INDEX_READ:
78 0 return "Reading of Index Pointer from dbx file failed";
79 0 case DBX_INDEX_UNDERREAD:
80 return
81 0 "Number of indexes read from dbx file is less than expected";
82 0 case DBX_INDEX_OVERREAD:
83 return
84 0 "Request was made for index reference greater than exists";
85 2 case DBX_INDEXCOUNT:
86 2 return "Index out of range";
87 0 case DBX_DATA_READ:
88 0 return "Reading of data from dbx file failed";
89 0 case DBX_NEWS_ITEM:
90 0 return "Item is a news item not an email";
91 0 default:
92 0 break;
93 }
94 0 return "Odd...an unknown error occured";
95 }
96  
97 2 void split_mail (pTHX_ DBX_EMAIL *self) {
98  
99 2 ▶ if (self->header)
Branch: 1 branch
BranchTrueFalseTotal
if (self->header) 1 1 2
100 1 return;
101
102 else {
103 char *ptr;
104 1 int count = 0;
105  
106 /* email data not yet loaded */
107 1 ▶ if (!self->email->email)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->email->email) 0 1 1
108 0 (void) dbx_get_email_body(((DBX_BOX*)SvIV((SV*)SvRV(self->dbx)))->dbx,
109 self->email);
110
111 1 ptr = self->email->email;
112
113 1 ▶ if (dbx_errno == DBX_DATA_READ) {
Branch: 1 branch
BranchTrueFalseTotal
if (dbx_errno == DBX_DATA_READ) { 0 1 1
114 /* A message can be there and not be there at the same time!
115 * Explanation:
116 * newsgroup items can be downloaded partially in OutlookX
117 * In this case dbx_get_email_body() will store nothing in
118 * self->email->email in which case header and body would be
119 * empty. then dbx_errno is set to DBX_DATA_READ which we
120 * don't consider an error here */
121 0 dbx_errno = DBX_NOERROR;
122 0 return;
123 }
124 1 ▶ if (dbx_errno == DBX_BADFILE)
Branch: 1 branch
BranchTrueFalseTotal
if (dbx_errno == DBX_BADFILE) 0 1 1
125 0 croak("dbx panic: file stream disappeared");
126  
127 1474 ▶ while (ptr+4) {
Branch: 1 branch
BranchTrueFalseTotal
while (ptr+4) { 1474 0 1474
128 /* two newlines is separator */
129 1474 ▶ if (strnEQ(ptr, "\r\n\r\n", 4)) {
Branch: 1 branch
BranchTrueFalseTotal
if (strnEQ(ptr, "\r\n\r\n", 4)) { 1 1473 1474
130 1 break;
131 }
132 1473 count++; ptr++;
133 }
134 /* +3: +"\r\n\0" */
135 1 self->header = (char*) safemalloc(sizeof(char) * (count+3));
136 1 self->body = (char*)
137 1 safemalloc(sizeof(char) * (strlen(self->email->email) - count));
138
139 1 strncpy(self->header, self->email->email, count+2);
140 1 self->header[count+2] = '\0';
141 /* +4 to ommit the two newlines ("\r\n\r\n") */
142 1 strcpy(self->body, ptr+4);
143 }
144 }
145
146 2 int datify (pTHX_ FILETIME *wintime, int method) {
147 2 dSP;
148 2 time_t time = FileTimeToUnixTime(wintime, NULL);
149 struct tm *tstruct;
150 2 (void) POPs; /* removing pending object which is in ST(0) */
151  
152 2 ▶ if (method == 0) /* localtime */
Branch: 1 branch
BranchTrueFalseTotal
if (method == 0) /* localtime */ 0 2 2
153 0 tstruct = localtime(&time);
154 else /* gmtime */
155 2 tstruct = gmtime(&time);
156
157 2 ▶ if (GIMME == G_ARRAY) {
Branch: 2 branches
BranchTrueFalseTotal
if (GIMME == G_ARRAY) { 2 0 2
if (GIMME == G_ARRAY) { 0 2 2
158 0 ▶ EXTEND(SP, 9);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 9); 0 0 0
159 0 PUSHs(sv_2mortal(newSViv(tstruct->tm_sec)));
160 0 PUSHs(sv_2mortal(newSViv(tstruct->tm_min)));
161 0 PUSHs(sv_2mortal(newSViv(tstruct->tm_hour)));
162 0 PUSHs(sv_2mortal(newSViv(tstruct->tm_mday)));
163 0 PUSHs(sv_2mortal(newSViv(tstruct->tm_mon)));
164 0 PUSHs(sv_2mortal(newSViv(tstruct->tm_year)));
165 0 PUSHs(sv_2mortal(newSViv(tstruct->tm_wday)));
166 0 PUSHs(sv_2mortal(newSViv(tstruct->tm_yday)));
167 0 PUSHs(sv_2mortal(newSViv(tstruct->tm_isdst)));
168 0 PUTBACK;
169 0 return 9;
170 } else {
171 2 SV *str = newSVpvf("%s %s %2d %02d:%02d:%02d %d",
172 dayname[tstruct->tm_wday],
173 monname[tstruct->tm_mon],
174 tstruct->tm_mday,
175 tstruct->tm_hour,
176 tstruct->tm_min,
177 tstruct->tm_sec,
178 tstruct->tm_year + 1900);
179 2 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 2 2
180 2 PUSHs(sv_2mortal(str));
181 2 PUTBACK;
182 2 return 1;
183 }
184 }
185  
186 0 int get_folder (SV *o, int index, SV **sv) {
187 DBX_FOLDER *folder;
188 0 DBX_BOX *dbx = (DBX_BOX*)SvIV(SvRV(o));
189 0 DBXFOLDER *ret = (DBXFOLDER*)dbx_get(dbx->dbx, index, 0);
190 0 New(0, folder, 1, DBX_FOLDER);
191 0 folder->dbx = o;
192 0 folder->folder = ret;
193 0 folder->fullpath = Nullav;
194 0 *sv = sv_setref_pv(newSV(0), "Mail::Transport::Dbx::Folder", (void*)folder);
195 0 SvREFCNT_inc(o);
196 0 return ret->id;
197 }
198
199 MODULE = Mail::Transport::Dbx PACKAGE = Mail::Transport::Dbx
200  
201 INCLUDE: const-xs.inc
202 PROTOTYPES: DISABLED
203  
204 DBX_BOX *
205 new (CLASS, dbx)
206 char *CLASS;
207 SV *dbx;
208 PREINIT:
209 STRLEN len;
210 CODE:
211 3 New(0, RETVAL, 1, DBX_BOX);
212 3 RETVAL->subfolders = NULL;
213 3 ▶ if (glob_ref(dbx) && !errno)
Branch: 3 branches
BranchTrueFalseTotal
if (glob_ref(dbx) && !errno) 0 3 3
if (glob_ref(dbx) && !errno) 0 0 0
if (glob_ref(dbx) && !errno) 0 0 0
214 0 RETVAL->dbx = dbx_open_stream(sv_to_file(dbx));
215 else
216 3 RETVAL->dbx = dbx_open(SvPV(dbx, len));
217  
218 3 ▶ if (!RETVAL->dbx)
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL->dbx) 0 3 3
219 0 croak("%s", errstr());
220  
221 OUTPUT:
222 RETVAL
223  
224 void
225 get (self, index)
226 SV *self;
227 int index;
228 PREINIT:
229 void *ret_type;
230 DBX_BOX *dbx;
231 CODE:
232 5 dbx = (DBX_BOX*)SvIV((SV*)SvRV(self));
233 5 ret_type = dbx_get(dbx->dbx, index, 0);
234 5 ▶ if (!ret_type)
Branch: 1 branch
BranchTrueFalseTotal
if (!ret_type) 2 3 5
235 2 XSRETURN_UNDEF;
236  
237 /* objects derived from a DBX struct keep a pointer
238 * to this struct because it is needed later; so
239 * we need to increment the DBX's refcount */
240 3 SvREFCNT_inc(self);
241 3 ▶ if (dbx->dbx->type == DBX_TYPE_EMAIL) {
Branch: 1 branch
BranchTrueFalseTotal
if (dbx->dbx->type == DBX_TYPE_EMAIL) { 3 0 3
242 DBX_EMAIL *ret;
243 3 New(0, ret, 1, DBX_EMAIL);
244 3 ST(0) = sv_newmortal();
245 3 ret->dbx = self;
246 3 ret->email = (DBXEMAIL*) ret_type;
247 3 ret->header = NULL;
248 3 ret->body = NULL;
249 3 sv_setref_pv(ST(0), "Mail::Transport::Dbx::Email", (void*)ret);
250 3 XSRETURN(1);
251 }
252 0 ▶ else if (dbx->dbx->type == DBX_TYPE_FOLDER) {
Branch: 1 branch
BranchTrueFalseTotal
else if (dbx->dbx->type == DBX_TYPE_FOLDER) { 0 0 0
253 0 ▶ if (!dbx->subfolders) {
Branch: 1 branch
BranchTrueFalseTotal
if (!dbx->subfolders) { 0 0 0
254 int id;
255 SV *sv;
256 0 Newz(0, dbx->subfolders, dbx->dbx->indexCount, SV*);
257 /* New(0, dbx->indexid, dbx->indexsize = dbx->dbx->indexCount, int); */
258 0 id = get_folder(self, index, &dbx->subfolders[index]);
259 /*
260 if (id >= dbx->indexsize) {
261 dbx->indexsize = id+1;
262 Renew(dbx->indexid, dbx->indexsize, int);
263 }
264 dbx->indexid[id] = index;
265 */
266 0 ST(0) = sv_mortalcopy(dbx->subfolders[index]);
267 } else
268 0 ST(0) = sv_mortalcopy(dbx->subfolders[index]);
269 //SvREFCNT_inc(self);
270 0 XSRETURN(1);
271 }
272  
273 int
274 error (...)
275 CODE:
276 0 ▶ RETVAL = dbx_errno;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = dbx_errno; 0 0 0
277 OUTPUT:
278 RETVAL
279  
280 char*
281 errstr (...)
282 CODE:
283 6 RETVAL = errstr();
284 OUTPUT:
285 RETVAL
286  
287 int
288 msgcount (self)
289 DBX_BOX *self;
290 CODE:
291 2 ▶ RETVAL = self->dbx->indexCount;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->dbx->indexCount; 0 2 2
292 OUTPUT:
293 RETVAL
294  
295 void
296 emails (object)
297 SV *object;
298 PREINIT:
299 DBX_BOX *self;
300 PPCODE:
301 0 self = (DBX_BOX*)SvIV((SV*)SvRV(object));
302 0 ▶ if (GIMME_V == G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_SCALAR) { 0 0 0
303 0 ▶ if (self->dbx->type == DBX_TYPE_EMAIL)
Branch: 1 branch
BranchTrueFalseTotal
if (self->dbx->type == DBX_TYPE_EMAIL) 0 0 0
304 0 XSRETURN_YES;
305 else
306 0 XSRETURN_NO;
307 }
308 0 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 0 0 0
309 int i;
310 0 ▶ if (self->dbx->type != DBX_TYPE_EMAIL || self->dbx->indexCount == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (self->dbx->type != DBX_TYPE_EMAIL || self->dbx->indexCount == 0) 0 0 0
if (self->dbx->type != DBX_TYPE_EMAIL || self->dbx->indexCount == 0) 0 0 0
311 0 XSRETURN_EMPTY;
312 0 ▶ for (i = 0; i < self->dbx->indexCount; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < self->dbx->indexCount; i++) { 0 0 0
313 0 SV *o = sv_newmortal();
314 0 void *item = dbx_get(self->dbx, i, 0);
315 0 DBX_EMAIL *ret = (DBX_EMAIL*) safemalloc(sizeof(DBX_EMAIL));
316 0 ret->dbx = object;
317 0 ret->email = (DBXEMAIL*) item;
318 0 ret->header = NULL;
319 0 ret->body = NULL;
320 0 SvREFCNT_inc(object);
321 0 o = sv_setref_pv(o, "Mail::Transport::Dbx::Email", (void*)ret);
322 0 ▶ XPUSHs(o);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(o); 0 0 0
323 }
324 0 XSRETURN(i);
325 }
326  
327 void
328 subfolders (object)
329 SV *object;
330 PREINIT:
331 DBX_BOX *self;
332 PPCODE:
333 0 self = (DBX_BOX*)SvIV((SV*)SvRV(object));
334  
335 0 ▶ if (GIMME_V == G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_SCALAR) { 0 0 0
336 0 ▶ if (self->dbx->type == DBX_TYPE_FOLDER)
Branch: 1 branch
BranchTrueFalseTotal
if (self->dbx->type == DBX_TYPE_FOLDER) 0 0 0
337 0 XSRETURN_YES;
338 else
339 0 XSRETURN_NO;
340 }
341  
342 0 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 0 0 0
343 int i;
344 0 ▶ if (self->dbx->type != DBX_TYPE_FOLDER || self->dbx->indexCount == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (self->dbx->type != DBX_TYPE_FOLDER || self->dbx->indexCount == 0) 0 0 0
if (self->dbx->type != DBX_TYPE_FOLDER || self->dbx->indexCount == 0) 0 0 0
345 0 XSRETURN_EMPTY;
346 0 ▶ if (self->subfolders) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->subfolders) { 0 0 0
347 0 ▶ EXTEND(SP, self->dbx->indexCount);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, self->dbx->indexCount); 0 0 0
EXTEND(SP, self->dbx->indexCount); 0 0 0
348 0 ▶ for (i = 0; i < self->dbx->indexCount; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < self->dbx->indexCount; i++) { 0 0 0
349 0 ▶ if (!self->subfolders[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (!self->subfolders[i]) { 0 0 0
350 0 int id = get_folder(object, i, &self->subfolders[i]);
351 /*
352 if (id >= self->indexsize) {
353 self->indexsize = id+1;
354 Renew(self->indexid, self->indexsize, int);
355 }
356 self->indexid[id] = i;
357 */
358 }
359 0 ST(i) = sv_mortalcopy(self->subfolders[i]);
360 0 SvREFCNT_inc(object);
361 }
362 0 XSRETURN(self->dbx->indexCount);
363 } else {
364 0 ▶ EXTEND(SP, self->dbx->indexCount);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, self->dbx->indexCount); 0 0 0
EXTEND(SP, self->dbx->indexCount); 0 0 0
365 0 New(0, self->subfolders, self->dbx->indexCount, SV*);
366 /* New(0, self->indexid, self->indexsize = self->dbx->indexCount, int); */
367 0 ▶ for (i = 0; i < self->dbx->indexCount; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < self->dbx->indexCount; i++) { 0 0 0
368 0 int id = get_folder(object, i, &self->subfolders[i]);
369 /*
370 if (id >= self->indexsize) {
371 self->indexsize = id+1;
372 Renew(self->indexid, self->indexsize, int);
373 }
374 self->indexid[id] = i;
375 */
376 0 PUSHs(sv_mortalcopy(self->subfolders[i]));
377 0 SvREFCNT_inc(object);
378 }
379 0 XSRETURN(self->dbx->indexCount);
380 }
381 }
382  
383 void
384 DESTROY (self)
385 DBX_BOX *self;
386 PREINIT:
387 register int i;
388 CODE:
389 3 IN_DBX_DESTROY = 1;
390 3 ▶ if (self->subfolders) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->subfolders) { 0 3 3
391 0 ▶ for (i = 0; i < self->dbx->indexCount; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < self->dbx->indexCount; i++) { 0 0 0
392 0 SvREFCNT_dec(self->subfolders[i]);
393 }
394 0 Safefree(self->subfolders);
395 /* Safefree(self->indexid); */
396 0 self->subfolders = NULL;
397 }
398 3 dbx_close(self->dbx);
399 3 IN_DBX_DESTROY = 0;
400
401 MODULE = Mail::Transport::Dbx PACKAGE = Mail::Transport::Dbx::Email
402  
403 char *
404 psubject (self)
405 DBX_EMAIL *self;
406 CODE:
407 2 RETVAL = self->email->psubject;
408 OUTPUT:
409 RETVAL
410  
411 char *
412 subject (self)
413 DBX_EMAIL *self;
414 CODE:
415 4 RETVAL = self->email->subject;
416 OUTPUT:
417 RETVAL
418  
419 char *
420 as_string (self)
421 DBX_EMAIL *self;
422 CODE:
423 3 ▶ if (!(RETVAL = self->email->email)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(RETVAL = self->email->email)) { 3 0 3
424 3 (void) dbx_get_email_body(((DBX_BOX*)SvIV((SV*)SvRV(self->dbx)))->dbx,
425 self->email);
426 3 ▶ if (dbx_errno == DBX_DATA_READ)
Branch: 1 branch
BranchTrueFalseTotal
if (dbx_errno == DBX_DATA_READ) 0 3 3
427 /* see comment in split_mail() */
428 0 XSRETURN_UNDEF;
429 3 RETVAL = self->email->email;
430 }
431 OUTPUT:
432 RETVAL
433  
434 char *
435 header (self)
436 DBX_EMAIL *self;
437 CODE:
438 1 split_mail(aTHX_ self);
439 1 ▶ if (!(RETVAL = self->header))
Branch: 1 branch
BranchTrueFalseTotal
if (!(RETVAL = self->header)) 0 1 1
440 0 XSRETURN_UNDEF;
441 OUTPUT:
442 RETVAL
443  
444 char *
445 body (self)
446 DBX_EMAIL *self;
447 CODE:
448 1 split_mail(aTHX_ self);
449 1 ▶ if (!(RETVAL = self->body))
Branch: 1 branch
BranchTrueFalseTotal
if (!(RETVAL = self->body)) 0 1 1
450 0 XSRETURN_UNDEF;
451 OUTPUT:
452 RETVAL
453  
454 char *
455 msgid (self)
456 DBX_EMAIL *self;
457 CODE:
458 2 RETVAL = self->email->messageid;
459 OUTPUT:
460 RETVAL
461  
462 char *
463 parents_ids (self)
464 DBX_EMAIL *self;
465 CODE:
466 2 RETVAL = self->email->parent_message_ids;
467 OUTPUT:
468 RETVAL
469  
470 char *
471 sender_name (self)
472 DBX_EMAIL *self;
473 CODE:
474 2 RETVAL = self->email->sender_name;
475 OUTPUT:
476 RETVAL
477  
478 char *
479 sender_address (self)
480 DBX_EMAIL *self;
481 CODE:
482 2 RETVAL = self->email->sender_address;
483 OUTPUT:
484 RETVAL
485  
486 char *
487 recip_name (self)
488 DBX_EMAIL *self;
489 CODE:
490 2 RETVAL = self->email->recip_name;
491 OUTPUT:
492 RETVAL
493  
494 char *
495 recip_address (self)
496 DBX_EMAIL *self;
497 CODE:
498 2 RETVAL = self->email->recip_address;
499 OUTPUT:
500 RETVAL
501  
502 char *
503 oe_account_name (self)
504 DBX_EMAIL *self;
505 CODE:
506 2 RETVAL = self->email->oe_account_name;
507 OUTPUT:
508 RETVAL
509  
510 char *
511 oe_account_num (self)
512 DBX_EMAIL *self;
513 CODE:
514 2 RETVAL = self->email->oe_account_num;
515 OUTPUT:
516 RETVAL
517  
518 char *
519 fetched_server (self)
520 DBX_EMAIL *self;
521 CODE:
522 2 RETVAL = self->email->fetched_server;
523 OUTPUT:
524 RETVAL
525  
526 void
527 rcvd_localtime (self)
528 DBX_EMAIL *self;
529 PPCODE:
530 0 XSRETURN(datify(aTHX_ &(self->email->date), 0));
531  
532 void
533 rcvd_gmtime (self)
534 DBX_EMAIL *self;
535 PPCODE:
536 2 XSRETURN(datify(aTHX_ &(self->email->date), 1));
537  
538 char *
539 date_received (self, ...)
540 DBX_EMAIL *self;
541 PREINIT:
542 2 char *format = "%a %b %e %H:%M:%S %Y";
543 STRLEN n_a;
544 2 ▶ size_t max_len = 25;
Branch: 1 branch
BranchTrueFalseTotal
size_t max_len = 25; 2 0 2
545 time_t time;
546 struct tm *tstruct;
547 char *string;
548 CODE:
549 2 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 0 2 2
550 0 format = (char *) SvPV(ST(1), n_a);
551 2 ▶ if (items > 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) 0 2 2
552 0 max_len = (int) SvIV(ST(2));
553  
554 2 time = FileTimeToUnixTime(&(self->email->date), NULL);
555  
556 2 ▶ if (items > 3 && SvTRUE(ST(3)))
Branch: 2 branches
BranchTrueFalseTotal
if (items > 3 && SvTRUE(ST(3))) 0 2 2
if (items > 3 && SvTRUE(ST(3))) 0 0 0
557 0 tstruct = gmtime(&time);
558 else
559 2 tstruct = localtime(&time);
560  
561 2 string = (char*) safemalloc(sizeof(char) * max_len);
562 2 strftime(string, max_len, format, tstruct);
563 2 RETVAL = string;
564 OUTPUT:
565 RETVAL
566  
567 int
568 is_seen (self)
569 DBX_EMAIL *self;
570 CODE:
571 2 ▶ RETVAL = (self->email->flag & DBX_EMAIL_FLAG_ISSEEN) > 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (self->email->flag & DBX_EMAIL_FLAG_ISSEEN) > 0 ? 1 : 0; 0 2 2
572 OUTPUT:
573 RETVAL
574  
575 int
576 is_email (self)
577 DBX_EMAIL *self;
578 CODE:
579 2 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 2 2
580 OUTPUT:
581 RETVAL
582  
583 int
584 is_folder (self)
585 DBX_EMAIL *self;
586 CODE:
587 2 ▶ RETVAL = 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 0; 0 2 2
588 OUTPUT:
589 RETVAL
590  
591 void
592 DESTROY (self)
593 DBX_EMAIL *self;
594 CODE:
595 3 ▶ if (self->header)
Branch: 1 branch
BranchTrueFalseTotal
if (self->header) 1 2 3
596 1 safefree(self->header);
597 3 ▶ if (self->body)
Branch: 1 branch
BranchTrueFalseTotal
if (self->body) 1 2 3
598 1 safefree(self->body);
599
600 3 dbx_free(((DBX_BOX*)SvIV((SV*)SvRV(self->dbx)))->dbx, self->email);
601 3 SvREFCNT_dec(self->dbx);
602 3 self->dbx = NULL;
603 3 safefree(self);
604
605  
606 MODULE = Mail::Transport::Dbx PACKAGE = Mail::Transport::Dbx::Folder
607  
608 int
609 num (self)
610 DBX_FOLDER *self;
611 CODE:
612 0 ▶ RETVAL = self->folder->num;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->folder->num; 0 0 0
613 OUTPUT:
614 RETVAL
615  
616 int
617 type (self)
618 DBX_FOLDER *self;
619 CODE:
620 0 ▶ RETVAL = self->folder->type;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->folder->type; 0 0 0
621 OUTPUT:
622 RETVAL
623  
624 char *
625 name (self)
626 DBX_FOLDER *self;
627 CODE:
628 0 RETVAL = self->folder->name;
629 OUTPUT:
630 RETVAL
631  
632 char *
633 file (self)
634 DBX_FOLDER *self;
635 CODE:
636 0 RETVAL = self->folder->fname;
637 OUTPUT:
638 RETVAL
639  
640 int
641 id (self)
642 DBX_FOLDER *self;
643 CODE:
644 0 ▶ RETVAL = self->folder->id;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->folder->id; 0 0 0
645 OUTPUT:
646 RETVAL
647  
648 int
649 parent_id (self)
650 DBX_FOLDER *self;
651 CODE:
652 0 ▶ RETVAL = self->folder->parentid;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->folder->parentid; 0 0 0
653 OUTPUT:
654 RETVAL
655  
656 int
657 is_email (self)
658 DBX_FOLDER *self;
659 CODE:
660 0 ▶ RETVAL = 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 0; 0 0 0
661 OUTPUT:
662 RETVAL
663  
664 int
665 is_folder (self)
666 DBX_FOLDER *self;
667 CODE:
668 0 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 0 0
669 OUTPUT:
670 RETVAL
671
672 DBX_BOX *
673 dbx (self)
674 DBX_FOLDER *self;
675 PREINIT:
676 0 char *CLASS = "Mail::Transport::Dbx"; /* used in typemap */
677 CODE:
678 0 ▶ if (!self->folder->fname)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->folder->fname) 0 0 0
679 0 XSRETURN_UNDEF;
680 0 New(0, RETVAL, 1, DBX_BOX);
681 0 RETVAL->subfolders = NULL;
682 0 RETVAL->dbx = dbx_open(self->folder->fname);
683 OUTPUT:
684 RETVAL
685  
686 SV*
687 _dbx (self)
688 DBX_FOLDER *self;
689 CODE:
690 0 RETVAL = self->dbx;
691 0 SvREFCNT_inc(RETVAL);
692 OUTPUT:
693 RETVAL
694  
695 # fullparse() below is slower than an equivalent implementation
696 # in Perl, so we don't use it
697 #if 0
698 void
699 fullpath (self)
700 DBX_FOLDER *self;
701 PREINIT:
702 register int i;
703 DBX_BOX *dbx;
704 int parent;
705 SV *sv;
706 AV *av;
707 int numret;
708 CODE:
709 av = self->fullpath;
710 if (av)
711 goto done;
712  
713 av = newAV();
714  
715 dbx = (DBX_BOX*)SvIV(SvRV(self->dbx));
716  
717 if (!dbx->subfolders) {
718 Newz(0, dbx->subfolders, dbx->dbx->indexCount, SV*);
719 New(0, dbx->indexid, dbx->indexsize = dbx->dbx->indexCount, int);
720 }
721
722 for (i = 0; i < dbx->dbx->indexCount; i++) {
723 if (!dbx->subfolders[i]) {
724 int id = get_folder(self->dbx, i, &(dbx->subfolders[i]));
725 if (id >= dbx->indexsize) {
726 dbx->indexsize = id+1;
727 Renew(dbx->indexid, dbx->indexsize, int);
728 }
729 dbx->indexid[id] = i;
730 }
731 }
732  
733 parent = self->folder->parentid;
734
735 while (1) {
736 SV *sv = dbx->subfolders[dbx->indexid[parent]];
737 DBX_FOLDER *f = (DBX_FOLDER*)SvIV(SvRV(sv));
738 av_push(av, newSVpv(f->folder->name, 0));
739 if (parent == 0)
740 break;
741 parent = f->folder->parentid;
742 }
743  
744 done:
745 numret = av_len(av) + 1;
746 for (i = 0; i < numret; i++)
747 ST(numret-i-1) = sv_mortalcopy(*av_fetch(av, i, FALSE));
748 ST(numret) = sv_2mortal(newSVpv(self->folder->name, 0));
749 XSRETURN(numret+1);
750  
751 #endif
752  
753 void
754 _DESTROY (self)
755 DBX_FOLDER *self;
756 PREINIT:
757 DBX_BOX *dbx;
758 SV *sv;
759 CODE:
760 /* we have a sort of circular destruction problem here:
761 * M::T::Dbx::DESTROY triggers M:T::DBX::Folder::DESTROY
762 * which itself decrements DBX_BOX' refcount so
763 * M::T::Dbx::DESTROY is called again which then calls
764 * M::T::DBX::Folder::DESTROY and so on. */
765 0 ▶ if (IN_DBX_DESTROY)
Branch: 1 branch
BranchTrueFalseTotal
if (IN_DBX_DESTROY) 0 0 0
766 0 XSRETURN_UNDEF;
767  
768 /* I don't know why I have to do this:
769 * without this check it will segfault under certain circumstances
770 * on threaded perls. */
771 0 ▶ if ((sv = (SV*)SvRV(self->dbx))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((sv = (SV*)SvRV(self->dbx))) { 0 0 0
772 0 dbx = (DBX_BOX*)SvIV(sv);
773 0 dbx_free(dbx->dbx, self->folder);
774 }
775
776 0 SvREFCNT_dec(self->dbx);
777 0 ▶ if (self->fullpath) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->fullpath) { 0 0 0
778 SV *sv;
779 0 ▶ while ((sv = av_pop(self->fullpath)) != &PL_sv_undef)
Branch: 1 branch
BranchTrueFalseTotal
while ((sv = av_pop(self->fullpath)) != &PL_sv_undef) 0 0 0
780 0 SvREFCNT_dec(sv);
781 0 SvREFCNT_dec(self->fullpath);
782 }
783 0 self->dbx = NULL;
784 0 Safefree(self);
785
786 MODULE = Mail::Transport::Dbx PACKAGE = Mail::Transport::Dbx::folder_info
787  
788 void
789 DESTROY (sv)
790 SV *sv;
791 CODE:
792 {
793 0 folder_info *finfo = (folder_info*)SvIV(SvRV(sv));
794 0 Safefree(finfo->name);
795 0 Safefree(finfo);
796 }
« blib/lib/Mail/Transport/Dbx.pm ↑ Summary const-xs.inc »