-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathripmime-api.c
144 lines (114 loc) · 3.44 KB
/
ripmime-api.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
/*----------------------------------------
* ripmime-api
*
* 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 "logger.h"
#include "ffget.h"
#include "strstack.h"
#include "mime.h"
#include "MIME_headers.h"
#include "ripmime-api.h"
char defaultdir[] = ".";
char version[] = "v1.4.0.1 - 30/08/2004 (C) PLDaniels http://www.pldaniels.com/ripmime";
/*-----------------------------------------------------------------\
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_object *rm)
{
rm->outputdir = defaultdir;
rm->mailpack = NULL;
LOGGER_set_output_mode(_LOGGER_STDOUT);
MIME_init();
MIME_set_uniquenames(1);
MIME_set_paranoid(0);
MIME_set_renamemethod(_MIME_RENAME_METHOD_INFIX);
MIME_set_verbosity(0);
return 0;
}
/*-----------------------------------------------------------------\
Function Name : main
Returns Type : int
----Parameter List
1. int argc,
2. char **argv,
------------------
Exit Codes :
Side Effects :
--------------------------------------------------------------------
Comments:
--------------------------------------------------------------------
Changes:
\------------------------------------------------------------------*/
int RIPMIME_decode( struct RIPMIME_object *rm, char *mailpack, char *outputdir )
{
int result = 0;
if (!mailpack)
{
LOGGER_log("%s:%d:RIPMIME_decode: mailpack filename is NULL\n",FL);
return 1;
} else {
rm->mailpack = strdup(mailpack);
}
if (!outputdir)
{
LOGGER_log("%s:%d:RIPMIME_decode: output directory is NULL\n",FL);
return 1;
} else {
rm->outputdir = strdup(outputdir);
}
// 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 (rm->outputdir[strlen (rm->outputdir) - 1] == '/')
{
rm->outputdir[strlen (rm->outputdir) - 1] = '\0';
}
// Create the output directory required as specified by the -d parameter
if (rm->outputdir != defaultdir)
{
result = mkdir (rm->outputdir, 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))
{
fprintf (stderr, "ripMIME: Cannot create directory '%s' (%s)\n",
rm->outputdir, strerror (errno));
return -1;
}
}
// Unpack the contents
MIMEH_set_outputdir(rm->outputdir);
MIME_unpack (rm->outputdir, rm->mailpack, 0);
// do any last minute things
MIME_close ();
return 0;
}
/*-END-----------------------------------------------------------*/