-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathripmime.c
774 lines (674 loc) · 27.2 KB
/
ripmime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
/*----------------------------------------
* ripMIME -
*
* Written by Paul L Daniels
*
* (C)2001 P.L.Daniels
* http://www.pldaniels.com/ripmime
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <syslog.h>
#include <signal.h>
#include <dirent.h>
#include "buildcodes.h"
#include "logger.h"
#include "ffget.h"
#include "mime.h"
#include "strstack.h"
#include "MIME_headers.h"
#define RIPMIME_ERROR_CANT_CREATE_OUTPUT_DIR 1
#define RIPMIME_ERROR_CANT_OPEN_INPUT_FILE 2
#define RIPMIME_ERROR_NO_INPUT_FILE 3
#define RIPMIME_ERROR_INSUFFICIENT_PARAMETERS 4
#define RIPMIME_ERROR_TIMEOUT 5
struct RIPMIME_globals
{
char *inputfile;
char *dir;
int use_return_codes;
int timeout;
int quiet;
int verbose_defects;
int verbose;
};
//-b [blankzone file name] : Dump the contents of the MIME blankzone to 'filename'
char defaultdir[] = ".";
struct RIPMIME_globals *ripmime_globals = NULL;
char version[] = "v1.4.1.0 - September 20, 2022 (C) PLDaniels http://www.pldaniels.com/ripmime";
char help[] = "ripMIME -i <mime file> -d <directory>"
"[-p prefix] [-e [header file]] [-vVh] [--version]"
"[--no_nameless] [--unique_names [--prefix|--postfix|--infix|--randprefix|--randpostfix|--randinfix]]"
"[--paranoid] [--mailbox] [--formdata] [--debug]"
"[--no-tnef] [--no-quotedprintable] [--no-uudecode]\n"
"Options available :\n"
"-i : Input MIME encoded file (use '-' to input from STDIN)\n"
"\tIf <mime file> is a directory, it will be recursed\n"
"-d : Output directory\n"
"-p : Specify prefix filename to be used on files without a filename (default 'text')\n"
"-e [headers file name] : Dump headers from mailpack (default '_headers_')\n"
"-v : Turn on verbosity\n"
"-q : Run quietly, do no report non-fatal errors\n"
"\n"
"--verbose-contenttype : Turn on verbosity of file content type\n"
"--verbose-oldstyle : Uses the v1.2.x style or filename reporting\n"
"--verbose-defects: Display a summary of defects in the email\n"
"--verbose-mime: Displays 'Email is MIME' if the email is MIME\n"
"--stdout : All reporting goes to stdout (Default)\n"
"--stderr : All reporting goes to stderr\n"
"--syslog : All reporting goes to syslog\n"
"\n"
"--no-paranoid : [ Deprecated ] Turns off strict ascii-alnum filenaming\n"
"--paranoid: Converts all filenames to strict 7-bit compliance\n"
"--name-by-type: Saves a given attachment by its content-type if it has no other name\n"
"--no-nameless : Do not save nameless attachments\n"
"--overwrite : Overwrite files if they have the same name on extraction\n"
"--unique-names : Dont overwrite existing files (This is the default behaviour)\n"
"--prefix : rename by putting unique code at the front of the filename\n"
"--postfix : rename by putting unique code at the end of the filename\n"
"--infix : rename by putting unique code in the middle of the filename\n"
"--randprefix : rename by putting unique code and random number at the front of the filename\n"
"--randpostfix : rename by putting unique code and random number at the end of the filename\n"
"--randinfix : rename by putting unique code and random number in the middle of the filename\n"
"\n"
"--mailbox : Process mailbox file\n"
"--formdata : Process as form data (from HTML form etc)\n"
"\n"
"--no-tnef : Turn off TNEF/winmail.dat decoding\n"
"--no-ole : Turn off OLE decoding\n"
"--no-uudecode : Turns off the facility of detecting UUencoded attachments in emails\n"
"--no-quotedprintable : Turns off the facility of decoding QuotedPrintable data\n"
"--no-doublecr : Turns off saving of double-CR embedded data\n"
"--no-mht : Turns off MHT (a Microsoft mailpack attachment format ) decoding\n"
"--no-multiple-filenames : Turns off the multiple filename exploit handling\n"
"\n"
"--disable-header-fix : Turns off attempts to fix broken headers\n"
"--disable-qmail-bounce : Turns off qmail bounced email testing\n"
"--recursion-max <level> : Set the maximum recursion level to 'level'\n"
"--timeout <seconds> : Set the maximum number of CPU seconds ripMIME can run for\n"
"\n"
"--debug : Produces detailed information about the whole decoding process\n"
"--extended-errors: Produces more return codes, even for non-fatals\n"
"-V --version : Give version information\n"
"--buildcodes : Give the build information (tstamp, date and system information)\n"
"-h : This message (help)\n\n\n";
/*-----------------------------------------------------------------\
Function Name : RIPMIME_report_filename_decoded
Returns Type : int
----Parameter List
1. char *filename,
2. char *contenttype,
------------------
Exit Codes :
Side Effects :
--------------------------------------------------------------------
Comments:
--------------------------------------------------------------------
Changes:
\------------------------------------------------------------------*/
int RIPMIME_report_filename_decoded (char *filename, char *contenttype)
{
char *p;
p = strrchr(filename,'/');
if (!p) p = filename; else p++;
if (contenttype != NULL)
{
LOGGER_log ("Decoding content-type=%s filename=%s", contenttype, p);
}
else
{
LOGGER_log ("Decoding filename=%s", p);
}
return 0;
}
/*-----------------------------------------------------------------\
Function Name : RIPMIME_parse_parameters
Returns Type : int
----Parameter List
1. struct RIPMIME_globals *glb,
2. int argc,
3. char **argv,
------------------
Exit Codes :
Side Effects :
--------------------------------------------------------------------
Comments:
--------------------------------------------------------------------
Changes:
\------------------------------------------------------------------*/
int RIPMIME_parse_parameters (struct RIPMIME_globals *glb, int argc, char **argv)
{
int i;
int result = 0;
MIME_set_filename_report_fn (RIPMIME_report_filename_decoded);
for (i = 1; i < argc; i++)
{
// if the first char of the argument is a '-', then we possibly have a flag
if (argv[i][0] == '-')
{
// test the 2nd char of the parameter
switch (argv[i][1])
{
case 'i':
if (argv[i][2] != '\0')
{
glb->inputfile = &argv[i][2];
}
else
{
i++;
if (i < argc)
{
glb->inputfile = argv[i];
}
else
{
LOGGER_log("ERROR: insufficient parameters after '-i'\n");
}
}
break;
case 'd':
if (argv[i][2] != '\0')
{
glb->dir = &(argv[i][2]);
}
else
{
i++;
if (i < argc)
{
glb->dir = argv[i];
}
else
{
LOGGER_log("ERROR: insufficient parameters after '-d'\n");
}
}
break;
case 'p':
if (argv[i][2] != '\0')
{
MIME_set_blankfileprefix (&argv[i][2]);
}
else
{
i++;
if (i < argc)
{
MIME_set_blankfileprefix (argv[i]);
}
else
{
LOGGER_log("ERROR: insufficient parameters after '-p'\n");
}
}
break; // this is in mime.h
case 'e':
MIME_set_dumpheaders (1);
if (argv[i][2] != '\0')
{
MIME_set_headersname (&argv[i][2]);
}
else
{
if ((i < (argc - 1)) && (argv[i + 1][0] != '-'))
MIME_set_headersname (argv[++i]);
}
break; // makes MIME dump out the headers to a file
#ifdef RIPMIME_BLANKZONE
case 'b':
if (argv[i][2] != '\0')
{
MIME_set_blankzone_filename (&argv[i][2]);
}
else
{
if ((i < (argc - 1)) && (argv[i + 1][0] != '-'))
MIME_set_blankzone_filename (argv[++i]);
}
break; // blankzone storage option
#endif
case 'v':
MIME_set_verbosity (1);
glb->verbose = 1;
break;
case 'q':
glb->quiet = 1;
MIME_set_quiet(glb->quiet);
break;
case 'V':
fprintf (stdout, "%s\n", version);
exit (1);
break;
case 'h':
fprintf (stdout, "%s\n", help);
exit (1);
break;
// if we get ANOTHER - symbol, then we have an extended flag
case '-':
if (strncmp (&(argv[i][2]), "verbose-contenttype", strlen ("verbose-contenttype")) == 0) {
MIME_set_verbosity_contenttype (1);
/** 20051117-0927:PLD:
** If client uses --verbose-mime, then make ripMIME report when it
** detects a MIME encoded email **/
} else if (strncmp(&(argv[i][2]), "verbose-mime", strlen("verbose-mime"))==0) {
MIME_set_report_MIME(1);
} else if (strncmp (&(argv[i][2]), "verbose-oldstyle", strlen ("verbose-oldstyle")) == 0) {
MIME_set_verbosity_12x_style (1);
MIME_set_filename_report_fn (NULL);
}
else if (strncmp (&(argv[i][2]), "verbose-defects",15) == 0)
{
glb->verbose_defects = 1;
MIME_set_verbose_defects(1);
}
else if (strncmp (&(argv[i][2]), "paranoid", 8) == 0)
{
MIME_set_paranoid (1);
}
else if (strncmp (&(argv[i][2]), "no_paranoid", 11) == 0)
{
MIME_set_paranoid (0);
}
else if (strncmp (&(argv[i][2]), "no-paranoid", 11) == 0)
{
MIME_set_paranoid (0);
}
else if (strncmp (&(argv[i][2]), "prefix", 6) == 0)
{
MIME_set_renamemethod (_MIME_RENAME_METHOD_PREFIX);
}
else if (strncmp (&(argv[i][2]), "postfix", 7) == 0)
{
MIME_set_renamemethod (_MIME_RENAME_METHOD_POSTFIX);
}
else if (strncmp (&(argv[i][2]), "infix", 5) == 0)
{
MIME_set_renamemethod (_MIME_RENAME_METHOD_INFIX);
}
/* New methods of generating file name: add counter and random number*/
else if (strncmp (&(argv[i][2]), "randprefix", 10) == 0)
{
MIME_set_renamemethod (_MIME_RENAME_METHOD_RANDPREFIX);
}
else if (strncmp (&(argv[i][2]), "randpostfix", 11) == 0)
{
MIME_set_renamemethod (_MIME_RENAME_METHOD_RANDPOSTFIX);
}
else if (strncmp (&(argv[i][2]), "randinfix", 9) == 0)
{
MIME_set_renamemethod (_MIME_RENAME_METHOD_RANDINFIX);
}
else if (strncmp (&(argv[i][2]), "overwrite", 9) == 0)
{
MIME_set_uniquenames (0);
}
else if (strncmp (&(argv[i][2]), "unique_names", 12) == 0)
{
MIME_set_uniquenames (1);
}
else if (strncmp (&(argv[i][2]), "unique-names", 12) == 0)
{
MIME_set_uniquenames (1);
}
else if (strncmp(&(argv[i][2]), "name-by-type", 12) == 0)
{
MIME_set_name_by_type(1);
}
else if (strncmp (&(argv[i][2]), "syslog", 9) == 0)
{
LOGGER_set_output_mode (_LOGGER_SYSLOG);
LOGGER_set_syslog_mode (LOG_MAIL | LOG_INFO);
}
else if (strncmp (&(argv[i][2]), "stderr", 10) == 0)
{
LOGGER_set_output_mode (_LOGGER_STDERR);
}
else if (strncmp (&(argv[i][2]), "stdout", 9) == 0)
{
LOGGER_set_output_mode (_LOGGER_STDOUT);
}
else if (strncmp (&(argv[i][2]), "no_nameless", 11) == 0)
{
MIME_set_no_nameless (1);
}
else if (strncmp (&(argv[i][2]), "no-nameless", 11) == 0)
{
MIME_set_no_nameless (1);
}
else if (strncmp (&(argv[i][2]), "debug", 5) == 0)
{
MIME_set_debug (1);
}
else if (strncmp (&(argv[i][2]), "mailbox", 7) == 0)
{
MIME_set_mailboxformat (1);
}
else if (strncmp(&(argv[i][2]), "formdata", 8) == 0)
{
// Form data usually contains embedded \0 sequences
// so we need to explicitly turn this off.
FFGET_set_allow_nul(1);
}
else if (strncmp (&(argv[i][2]), "no_uudecode", 11) == 0)
{
// We are transitioning away from negative-logic function
// names because they can cause confusion when reading, so
// from here on, we will use things like _set_foo() rather
// than _set_no_foo()
MIME_set_decode_uudecode(0);
}
else if (strncmp (&(argv[i][2]), "no-uudecode", 11) == 0)
{
MIME_set_decode_uudecode(0);
}
else if (strncmp (&(argv[i][2]), "no-tnef", 7) == 0)
{
MIME_set_decode_tnef (0);
}
else if (strncmp (&(argv[i][2]), "no-ole", 6) == 0)
{
MIME_set_decode_ole(0);
}
else if (strncmp (&(argv[i][2]), "no-base64", 9) == 0)
{
MIME_set_decode_base64(0);
}
else if (strncmp (&(argv[i][2]), "no-quotedprintable", strlen("no-quotedprintable")) == 0)
{
MIME_set_decode_qp(0);
}
else if (strncmp(&(argv[i][2]), "no-doublecr", strlen("no-doublecr")) == 0)
{
MIME_set_decode_doubleCR(0);
}
else if (strncmp(&(argv[i][2]), "no-mht", strlen("no-mht")) == 0)
{
MIME_set_decode_mht(0);
}
else if (strncmp(&(argv[i][2]), "disable-header-fix", strlen("disable-headerfix")) == 0) {
MIMEH_set_headerfix(0);
}
else if (strncmp(&(argv[i][2]), "qmail-bounce", strlen("qmail-bounce")) == 0)
{
MIME_set_header_longsearch(1);
}
else if (strncmp(&(argv[i][2]), "disable-qmail-bounce", strlen("disable-qmail-bounce")) == 0)
{
MIME_set_header_longsearch(0);
}
else if (strncmp(&(argv[i][2]), "no-multiple-filenames", strlen("no-multiple-filenames")) == 0)
{
MIME_set_multiple_filenames(0);
}
else if (strncmp(&(argv[i][2]), "recursion-max", strlen("recursion-max")) == 0)
{
if (argv[i+1] != NULL)
{
int level;
level = atoi(argv[i+1]);
if (level > 0)
{
MIME_set_recursion_level(level);
}
}
}
else if (strncmp(&(argv[i][2]), "timeout", strlen("timeout")) == 0)
{
if (argv[i+1] != NULL)
{
int seconds;
seconds = atoi(argv[i+1]);
if (seconds > 0)
{
glb->timeout = seconds;
}
}
}
else if (strncmp (&(argv[i][2]), "buildcodes", 10) == 0)
{
fprintf(stdout,"%s\n%s\n%s\n", BUILD_CODE, BUILD_DATE, BUILD_BOX);
exit(0);
}
else if (strncmp (&(argv[i][2]), "version", 7) == 0)
{
fprintf (stdout, "%s\n", version);
exit (0);
}
else if (strncmp(&(argv[i][2]), "extended-errors", strlen("extended-errors")) == 0)
{
glb->use_return_codes = 1;
}
else
{
LOGGER_log ("Cannot interpret option \"%s\"\n%s\n", argv[i],
help);
exit (1);
break;
}
break;
// else, just dump out the help message
default:
LOGGER_log ("Cannot interpret option \"%s\"\n%s\n", argv[i],
help);
exit (1);
break;
} // Switch argv[i][1]
} // if argv[i][0] == -
} // for
return result;
}
/*-----------------------------------------------------------------\
Function Name : RIPMIME_init
Returns Type : int
----Parameter List
1. struct RIPMIME_globals *glb,
------------------
Exit Codes :
Side Effects :
--------------------------------------------------------------------
Comments:
--------------------------------------------------------------------
Changes:
\------------------------------------------------------------------*/
int RIPMIME_init (struct RIPMIME_globals *glb)
{
glb->dir = defaultdir;
glb->inputfile = NULL;
glb->use_return_codes = 0;
glb->timeout = 0;
glb->quiet = 0;
glb->verbose_defects = 0;
glb->verbose = 0;
return 0;
}
/*-----------------------------------------------------------------\
Function Name : RIPMIME_signal_alarm
Returns Type : void
----Parameter List
1. int sig ,
------------------
Exit Codes :
Side Effects :
--------------------------------------------------------------------
Comments:
--------------------------------------------------------------------
Changes:
\------------------------------------------------------------------*/
void RIPMIME_signal_alarm( int sig )
{
if (ripmime_globals->quiet == 0) LOGGER_log("%s:%d:RIPMIME_signal_alarm: ripMIME took too long to complete. Mailpack is \"%s\", output dir is \"%s\"",FL, ripmime_globals->inputfile, ripmime_globals->dir );
exit(RIPMIME_ERROR_TIMEOUT);
}
/*-----------------------------------------------------------------\
Function Name : RIPMIME_unpack_single
Returns Type : int
----Parameter List
1. struct RIPMIME_globals *glb,
2. char *fname ,
------------------
Exit Codes :
Side Effects :
--------------------------------------------------------------------
Comments:
--------------------------------------------------------------------
Changes:
\------------------------------------------------------------------*/
int RIPMIME_unpack_single( struct RIPMIME_globals *glb, char *fname )
{
int result = 0;
/** Set the alarm timeout feature. **/
if (glb->timeout > 0) {
signal(SIGALRM, RIPMIME_signal_alarm);
alarm(glb->timeout);
}
MIMEH_set_outputdir (glb->dir);
result = MIME_unpack (glb->dir, fname, 0);
// do any last minute things
MIME_close ();
return result;
}
/*-----------------------------------------------------------------\
Function Name : RIPMIME_unpack
Returns Type : int
----Parameter List
1. struct RIPMIME_globals *glb ,
------------------
Exit Codes :
Side Effects :
--------------------------------------------------------------------
Comments:
--------------------------------------------------------------------
Changes:
\------------------------------------------------------------------*/
int RIPMIME_unpack( struct RIPMIME_globals *glb )
{
struct stat st;
int stat_result = 0;
int result = 0;
int input_is_directory = 0;
/** If we're not inputting from STDIN, check to see if the
** input is a directory **/
if (strcmp(glb->inputfile,"-")!=0) {
stat_result = stat(glb->inputfile, &st);
if (stat_result != 0) return -1;
if (S_ISDIR(st.st_mode)) input_is_directory = 1;
}
if (input_is_directory == 1) {
/** Unpack all files in directory **/
DIR *dir;
struct dirent *dir_entry;
fprintf(stderr,"input file is a directory, recursing\n");
dir = opendir(glb->inputfile);
if (dir == NULL) return -1;
do {
/** Check every entry in the directory provided and if it's a file
** try to unpack it **/
char fullfilename[1024];
dir_entry = readdir( dir );
if (dir_entry == NULL) break;
if (strcmp(dir_entry->d_name, ".")==0) continue;
if (strcmp(dir_entry->d_name, "..")==0) continue;
snprintf(fullfilename,sizeof(fullfilename),"%s/%s", glb->inputfile, dir_entry->d_name);
stat_result = stat( fullfilename, &st );
if (stat_result != 0) continue;
if (S_ISREG(st.st_mode)) {
/** If the directory entry is a file, then unpack it **/
fprintf(stdout,"Unpacking mailpack %s\n",fullfilename);
result = RIPMIME_unpack_single(glb, fullfilename);
}
} while (dir_entry != NULL); /** While more files in the directory **/
closedir( dir );
} else {
/** If the supplied file was actually a normal file, then decode normally **/
result = RIPMIME_unpack_single( glb, glb->inputfile );
}
return result;
}
/*-----------------------------------------------------------------\
Function Name : main
Returns Type : int
----Parameter List
1. int argc,
2. char **argv,
------------------
Exit Codes :
Side Effects :
--------------------------------------------------------------------
Comments:
--------------------------------------------------------------------
Changes:
\------------------------------------------------------------------*/
int main (int argc, char **argv)
{
struct RIPMIME_globals glb;
int result = 0;
/* if the user has just typed in "ripmime" and nothing else, then we had better give them
* the rundown on how to use this program */
if (argc < 2)
{
fprintf (stderr, "%s\n%s", version, help);
return RIPMIME_ERROR_INSUFFICIENT_PARAMETERS;
}
// Set the global pointer ripmime_globals to point to
// the glb struct, so that if we have a timeout condition
// we can use the data
ripmime_globals = &glb;
// Set up our initial logging mode - so that we can always get
// report messages if need be.
LOGGER_set_output_mode (_LOGGER_STDOUT);
// Perform system initialisations
MIME_init ();
RIPMIME_init (&glb);
// Setup our default behaviours */
MIME_set_uniquenames (1);
MIME_set_paranoid (0);
MIME_set_header_longsearch(1); // 20040310-0117:PLD - Added by default as it seems stable, use --disable-qmail-bounce to turn off
MIME_set_renamemethod (_MIME_RENAME_METHOD_INFIX);
RIPMIME_parse_parameters (&glb, argc, argv);
// if our input filename wasn't specified, then we better let the user know!
if (!glb.inputfile)
{
LOGGER_log("Error: No input file was specified\n");
return RIPMIME_ERROR_NO_INPUT_FILE;
}
// Fire up the randomizer
srand (time (NULL));
// clean up the output directory name if required (remove any trailing /'s, as suggested by James Cownie 03/02/2001
if (glb.dir[strlen (glb.dir) - 1] == '/')
{
glb.dir[strlen (glb.dir) - 1] = '\0';
}
// Create the output directory required as specified by the -d parameter
if (glb.dir != defaultdir)
{
result = mkdir (glb.dir, S_IRWXU);
// if we had a problem creating a directory, and it wasn't just
// due to the directory already existing, then we have a bit of
// a problem on our hands, hence, report it.
//
if ((result == -1) && (errno != EEXIST))
{
LOGGER_log("ripMIME: Cannot create directory '%s' (%s)\n",
glb.dir, strerror (errno));
return RIPMIME_ERROR_CANT_CREATE_OUTPUT_DIR;
}
}
// Unpack the contents
result = RIPMIME_unpack(&glb);
// Possible exit codes include;
// 0 - all okay
// 240 - processing stopped due to recursion limit
if (glb.use_return_codes == 0) result = 0;
return result;
}
/*-END-----------------------------------------------------------*/