Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
edadcf90
...
edadcf908400977589b0a921e196998df3f2f8b0
authored
2000-06-07 04:07:30 +0000
by
Alain Magloire
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
cleanup.
1 parent
599736a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
43 deletions
mailbox/include/public/header.h
mailbox/mime.c
mailbox/include/public/header.h
View file @
edadcf9
...
...
@@ -58,6 +58,7 @@ extern "C" {
#define MU_HEADER_STATUS "Status"
#define MU_HEADER_CONTENT_LENGTH "Content-Length"
#define MU_HEADER_CONTENT_TYPE "Content-Type"
#define MU_HEADER_CONTENT_ENCODING "Content-transfer-encoding"
#define MU_HEADER_MIME_VERSION "MIME-Version"
/* Mime support header attribute */
...
...
mailbox/mime.c
View file @
edadcf9
...
...
@@ -41,7 +41,7 @@ static int _mime_append_part( mime_t mime, int body_offset, int body_len, int en
{
struct
_mime_part
*
mime_part
,
**
part_arr
;
int
ret
;
if
(
(
mime_part
=
calloc
(
1
,
sizeof
(
*
mime_part
))
)
==
NULL
)
return
ENOMEM
;
if
(
(
ret
=
header_init
(
&
mime_part
->
hdr
,
mime
->
header_buf
,
mime
->
header_length
,
mime_part
)
)
!=
0
)
{
...
...
@@ -80,14 +80,14 @@ static int _mime_append_part( mime_t mime, int body_offset, int body_len, int en
static
struct
_mime_part
*
_mime_get_owner
(
mime_t
mime
,
message_t
msg
)
{
int
i
;
for
(
i
=
0
;
i
<
mime
->
nmtp_parts
;
i
++
)
{
if
(
mime
->
mtp_parts
[
i
]
==
msg
->
owner
)
return
mime
->
mtp_parts
[
i
];
}
return
NULL
;
}
static
char
*
_strltrim
(
char
*
str
)
{
char
*
p
;
...
...
@@ -100,7 +100,7 @@ static char *_strltrim(char *str)
static
char
*
_strttrim
(
char
*
str
)
{
char
*
p
;
for
(
p
=
str
+
strlen
(
str
)
-
1
;
isspace
(
*
p
)
&&
p
>=
str
;
--
p
)
;
*++
p
=
'\0'
;
...
...
@@ -115,28 +115,28 @@ char *_strtrim(char *str);
|| ((c) == '@') || ((c) == ',') || ((c) == ';') || ((c) == ':') \
|| ((c) == '\\') || ((c) == '"') || ((c) == '.') || ((c) == '[') \
|| ((c) == ']') )
static
void
_mime_munge_content_header
(
char
*
field_body
)
{
char
*
p
,
*
e
,
*
str
=
field_body
;
int
quoted
=
0
;
_strtrim
(
field_body
);
if
(
(
e
=
p
=
strchr
(
str
,
';'
)
)
==
NULL
)
return
;
e
++
;
return
;
e
++
;
while
(
*
e
&&
isspace
(
*
e
)
)
/* remove space upto param */
e
++
;
memmove
(
p
+
1
,
e
,
strlen
(
e
)
+
1
);
e
=
p
+
1
;
while
(
*
e
&&
*
e
!=
'='
)
/* find end of value */
e
++
;
e
=
p
=
e
+
1
;
while
(
*
e
&&
(
quoted
||
!
_ISSPECIAL
(
*
e
)
||
!
isspace
(
*
e
)
)
)
{
if
(
*
e
==
'\\'
)
{
/* escaped */
memmove
(
e
,
e
+
1
,
strlen
(
e
)
+
2
);
memmove
(
e
,
e
+
1
,
strlen
(
e
)
+
2
);
}
else
if
(
*
e
==
'\"'
)
quoted
=
~
quoted
;
e
++
;
...
...
@@ -147,7 +147,7 @@ static char *_mime_get_param(char *field_body, const char *param, int *len)
{
char
*
str
,
*
p
,
*
v
,
*
e
;
int
quoted
=
0
,
was_quoted
=
0
;
if
(
len
==
NULL
||
(
str
=
field_body
)
==
NULL
)
return
NULL
;
...
...
@@ -162,7 +162,7 @@ static char *_mime_get_param(char *field_body, const char *param, int *len)
if
(
*
e
==
'\"'
)
quoted
=
~
quoted
,
was_quoted
=
1
;
else
(
*
len
)
++
;
(
*
len
)
++
;
e
++
;
}
if
(
strncasecmp
(
p
,
param
,
strlen
(
param
))
)
{
/* no match jump to next */
...
...
@@ -171,7 +171,7 @@ static char *_mime_get_param(char *field_body, const char *param, int *len)
}
else
return
was_quoted
?
v
+
1
:
v
;
/* return unquted value */
}
}
return
NULL
;
}
...
...
@@ -205,11 +205,11 @@ static int _mime_parse_mpart_message(mime_t mime)
char
*
cp
,
*
cp2
;
int
blength
,
body_length
,
body_offset
,
ret
;
size_t
nbytes
;
if
(
!
(
mime
->
flags
&
MIME_PARSER_ACTIVE
)
)
{
char
*
boundary
;
int
len
;
if
(
(
ret
=
_mime_setup_buffers
(
mime
)
)
!=
0
)
return
ret
;
if
(
(
boundary
=
_mime_get_param
(
mime
->
content_type
,
"boundary"
,
&
len
)
)
==
NULL
)
...
...
@@ -217,7 +217,7 @@ static int _mime_parse_mpart_message(mime_t mime)
if
(
(
mime
->
boundary
=
calloc
(
1
,
len
+
1
)
)
==
NULL
)
return
ENOMEM
;
strncpy
(
mime
->
boundary
,
boundary
,
len
);
mime
->
cur_offset
=
0
;
mime
->
line_ndx
=
0
;
mime
->
parser_state
=
MIME_STATE_SCAN_BOUNDARY
;
...
...
@@ -225,7 +225,7 @@ static int _mime_parse_mpart_message(mime_t mime)
}
body_length
=
mime
->
body_length
;
body_offset
=
mime
->
body_offset
;
while
(
(
ret
=
stream_read
(
mime
->
stream
,
mime
->
cur_buf
,
mime
->
buf_size
,
mime
->
cur_offset
,
&
nbytes
)
)
==
0
&&
nbytes
)
{
cp
=
mime
->
cur_buf
;
while
(
nbytes
)
{
...
...
@@ -241,14 +241,14 @@ static int _mime_parse_mpart_message(mime_t mime)
cp2
=
mime
->
cur_line
[
0
]
==
'\n'
?
mime
->
cur_line
+
1
:
mime
->
cur_line
;
blength
=
strlen
(
mime
->
boundary
);
if
(
mime
->
line_ndx
>=
blength
)
{
if
(
(
!
strncasecmp
(
cp2
,
"--"
,
2
)
&&
!
strncasecmp
(
cp2
+
2
,
mime
->
boundary
,
blength
)
)
if
(
(
!
strncasecmp
(
cp2
,
"--"
,
2
)
&&
!
strncasecmp
(
cp2
+
2
,
mime
->
boundary
,
blength
)
)
||
!
strncasecmp
(
cp2
,
mime
->
boundary
,
blength
)
)
{
mime
->
parser_state
=
MIME_STATE_HEADERS
;
mime
->
flags
&=
~
MIME_PARSER_HAVE_CR
;
body_length
=
mime
->
cur_offset
-
body_offset
-
mime
->
line_ndx
+
1
;
if
(
mime
->
header_length
)
/* this skips the preamble */
_mime_append_part
(
mime
,
body_offset
,
body_length
,
FALSE
);
if
(
(
cp2
+
blength
+
2
<
cp
&&
!
strncasecmp
(
cp2
+
2
+
blength
,
"--"
,
2
)
)
||
if
(
(
cp2
+
blength
+
2
<
cp
&&
!
strncasecmp
(
cp2
+
2
+
blength
,
"--"
,
2
)
)
||
!
strncasecmp
(
cp2
+
blength
,
"--"
,
2
)
)
{
/* very last boundary */
break
;
}
...
...
@@ -256,7 +256,7 @@ static int _mime_parse_mpart_message(mime_t mime)
break
;
}
}
mime
->
line_ndx
=
0
;
mime
->
line_ndx
=
0
;
mime
->
cur_line
[
0
]
=
*
cp
;
/* stay in this state but leave '\n' at begining */
break
;
case
MIME_STATE_HEADERS
:
...
...
@@ -265,7 +265,7 @@ static int _mime_parse_mpart_message(mime_t mime)
if
(
mime
->
line_ndx
==
1
||
mime
->
cur_line
[
0
]
==
'\r'
)
{
mime
->
parser_state
=
MIME_STATE_BEGIN_LINE
;
body_offset
=
mime
->
cur_offset
+
1
;
}
}
mime
->
line_ndx
=
-
1
;
break
;
}
...
...
@@ -278,12 +278,12 @@ static int _mime_parse_mpart_message(mime_t mime)
mime
->
cur_offset
++
;
nbytes
--
;
cp
++
;
}
}
if
(
mime
->
flags
&
MIME_INCREAMENTAL_PARSER
)
{
ret
=
EAGAIN
;
break
;
break
;
}
}
}
mime
->
body_length
=
body_length
;
mime
->
body_offset
=
body_offset
;
if
(
ret
!=
EAGAIN
)
{
/* finished cleanup */
...
...
@@ -296,8 +296,8 @@ static int _mime_parse_mpart_message(mime_t mime)
static
int
_mime_message_read
(
stream_t
stream
,
char
*
buf
,
size_t
buflen
,
off_t
off
,
size_t
*
nbytes
)
{
struct
_mime_part
*
mime_part
=
stream
->
owner
;
s
s
ize_t
read_len
;
size_t
read_len
;
if
(
nbytes
==
NULL
)
return
(
EINVAL
);
...
...
@@ -336,9 +336,9 @@ int mime_init(mime_t *pmime, message_t msg, int flags)
mime
->
msg
=
msg
;
mime
->
buf_size
=
MIME_DFLT_BUF_SIZE
;
message_get_stream
(
msg
,
&
(
mime
->
stream
));
}
}
}
}
}
else
{
/* create a floating message to contain this new mime message */
if
(
(
ret
=
message_init
(
&
msg
,
NULL
)
)
==
0
)
{
if
(
(
ret
=
message_get_stream
(
msg
,
&
(
mime
->
stream
))
)
==
0
)
{
...
...
@@ -364,22 +364,22 @@ void mime_destroy(mime_t *pmime)
mime_t
mime
;
struct
_mime_part
*
mime_part
;
int
i
;
if
(
pmime
&&
*
pmime
)
{
mime
=
*
pmime
;
if
(
mime
->
mtp_parts
!=
NULL
)
{
for
(
i
=
0
;
i
<
mime
->
nmtp_parts
;
i
++
)
{
mime_part
=
mime
->
mtp_parts
[
i
];
if
(
mime_part
->
msg
)
for
(
i
=
0
;
i
<
mime
->
nmtp_parts
;
i
++
)
{
mime_part
=
mime
->
mtp_parts
[
i
];
if
(
mime_part
->
msg
)
message_destroy
(
&
mime_part
->
msg
,
mime_part
);
else
header_destroy
(
&
mime_part
->
hdr
,
mime_part
);
}
}
if
(
mime
->
cap_msgs
!=
NULL
)
{
for
(
i
=
0
;
i
<
mime
->
ncap_msgs
;
i
++
)
{
mime_part
=
mime
->
cap_msgs
[
i
];
if
(
mime_part
->
msg
)
for
(
i
=
0
;
i
<
mime
->
ncap_msgs
;
i
++
)
{
mime_part
=
mime
->
cap_msgs
[
i
];
if
(
mime_part
->
msg
)
message_destroy
(
&
mime_part
->
msg
,
mime_part
);
else
header_destroy
(
&
mime_part
->
hdr
,
mime_part
);
...
...
@@ -391,7 +391,7 @@ void mime_destroy(mime_t *pmime)
free
(
mime
->
cur_buf
);
if
(
mime
->
cur_line
)
free
(
mime
->
cur_line
);
if
(
mime
->
boundary
)
if
(
mime
->
boundary
)
free
(
mime
->
boundary
);
if
(
mime
->
header_buf
)
free
(
mime
->
header_buf
);
...
...
@@ -414,7 +414,7 @@ int mime_get_part(mime_t mime, int part, message_t *msg)
size_t
hsize
=
0
;
stream_t
stream
;
struct
_mime_part
*
mime_part
;
if
(
(
ret
=
mime_get_num_parts
(
mime
,
&
nmtp_parts
)
)
==
0
)
{
if
(
part
<
1
||
part
>
nmtp_parts
)
return
EINVAL
;
...
...
@@ -450,10 +450,10 @@ int mime_unencapsulate(mime_t mime, message_t msg, message_t *newmsg)
header_t
hdr
;
stream_t
stream
;
struct
_mime_part
*
mime_part
;
if
(
mime
==
NULL
||
msg
==
NULL
||
newmsg
==
NULL
||
mime
->
flags
&
MIME_NEW_MESSAGE
)
return
EINVAL
;
if
(
mime
->
msg
!=
msg
&&
(
mime_part
=
_mime_get_owner
(
mime
,
msg
)
)
==
NULL
)
/* I don't know about or own this message */
return
EPERM
;
...
...
@@ -515,13 +515,13 @@ int mime_unencapsulate(mime_t mime, message_t msg, message_t *newmsg)
}
}
}
return
ret
;
return
ret
;
}
int
mime_get_num_parts
(
mime_t
mime
,
int
*
nmtp_parts
)
{
int
ret
=
0
;
if
(
mime
->
nmtp_parts
==
0
||
mime
->
flags
&
MIME_PARSER_ACTIVE
)
{
if
(
mime_is_multi_part
(
mime
)
)
{
if
(
(
ret
=
_mime_parse_mpart_message
(
mime
)
)
!=
0
)
...
...
@@ -531,7 +531,7 @@ int mime_get_num_parts(mime_t mime, int *nmtp_parts)
}
*
nmtp_parts
=
mime
->
nmtp_parts
;
return
(
ret
);
}
int
mime_add_part
(
mime_t
mime
,
message_t
msg
)
...
...
Please
register
or
sign in
to post a comment