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
e939545a
...
e939545a5d54df95c5a05f8efc597ea81604e586
authored
2001-12-16 16:58:49 +0000
by
Sam Roberts
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
gnu indented
1 parent
78a5a246
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
87 deletions
examples/mimetest.c
mailbox/attachment.c
examples/mimetest.c
View file @
e939545
...
...
@@ -37,7 +37,7 @@ char from[256];
char
subject
[
256
];
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
mailbox_t
mbox
=
NULL
;
int
ret
;
...
...
@@ -59,64 +59,73 @@ main(int argc, char **argv)
list_append
(
bookie
,
imap_record
);
}
if
(
(
ret
=
mailbox_create_default
(
&
mbox
,
mailbox_name
)
)
!=
0
)
{
fprintf
(
stderr
,
"could not create - %s
\n
"
,
strerror
(
ret
));
if
((
ret
=
mailbox_create_default
(
&
mbox
,
mailbox_name
))
!=
0
)
{
fprintf
(
stderr
,
"could not create - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
/* Debuging Trace. */
if
(
0
)
{
if
(
0
)
{
mu_debug_t
debug
;
mailbox_get_debug
(
mbox
,
&
debug
);
mu_debug_set_level
(
debug
,
MU_DEBUG_TRACE
|
MU_DEBUG_PROT
);
mu_debug_set_level
(
debug
,
MU_DEBUG_TRACE
|
MU_DEBUG_PROT
);
}
/* Open the mailbox for reading only. */
if
(
(
ret
=
mailbox_open
(
mbox
,
MU_STREAM_RDWR
)
)
!=
0
)
{
fprintf
(
stderr
,
"could not open - %s
\n
"
,
strerror
(
ret
));
if
((
ret
=
mailbox_open
(
mbox
,
MU_STREAM_RDWR
))
!=
0
)
{
fprintf
(
stderr
,
"could not open - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
/* Iterator through the entire message set. */
mailbox_messages_count
(
mbox
,
&
count
);
for
(
i
=
1
;
i
<=
count
;
++
i
)
{
for
(
i
=
1
;
i
<=
count
;
++
i
)
{
message_t
msg
;
header_t
hdr
;
size_t
nparts
;
size_t
msize
;
if
((
ret
=
mailbox_get_message
(
mbox
,
i
,
&
msg
)
)
!=
0
)
{
fprintf
(
stderr
,
"mailbox_get_message - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
if
((
ret
=
mailbox_get_message
(
mbox
,
i
,
&
msg
))
!=
0
)
{
fprintf
(
stderr
,
"mailbox_get_message - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
if
((
ret
=
message_size
(
msg
,
&
msize
)
)
!=
0
)
{
fprintf
(
stderr
,
"message_size - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
if
((
ret
=
message_size
(
msg
,
&
msize
))
!=
0
)
{
fprintf
(
stderr
,
"message_size - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
if
((
ret
=
message_get_header
(
msg
,
&
hdr
)
)
!=
0
)
{
fprintf
(
stderr
,
"message_get_header - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
if
((
ret
=
message_get_header
(
msg
,
&
hdr
))
!=
0
)
{
fprintf
(
stderr
,
"message_get_header - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
header_get_value
(
hdr
,
MU_HEADER_FROM
,
from
,
sizeof
(
from
),
NULL
);
header_get_value
(
hdr
,
MU_HEADER_SUBJECT
,
subject
,
sizeof
(
subject
),
NULL
);
printf
(
"From: %s
\t
Subject: %s
\n
"
,
from
,
subject
);
if
(
(
ret
=
message_get_num_parts
(
msg
,
&
nparts
)
)
!=
0
)
{
fprintf
(
stderr
,
"message_get_num_parts - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
printf
(
"-- Number of parts in message - %d
\n
"
,
nparts
);
printf
(
"-- Total message size - %d
\n
"
,
msize
);
message_display_parts
(
msg
,
"
\t
"
);
}
mailbox_close
(
mbox
);
mailbox_destroy
(
&
mbox
);
header_get_value
(
hdr
,
MU_HEADER_SUBJECT
,
subject
,
sizeof
(
subject
),
NULL
);
printf
(
"From: %s
\t
Subject: %s
\n
"
,
from
,
subject
);
if
((
ret
=
message_get_num_parts
(
msg
,
&
nparts
))
!=
0
)
{
fprintf
(
stderr
,
"message_get_num_parts - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
printf
(
"-- Number of parts in message - %d
\n
"
,
nparts
);
printf
(
"-- Total message size - %d
\n
"
,
msize
);
message_display_parts
(
msg
,
"
\t
"
);
}
mailbox_close
(
mbox
);
mailbox_destroy
(
&
mbox
);
return
0
;
}
char
buf
[
2048
];
void
message_display_parts
(
message_t
msg
,
char
*
indent
)
message_display_parts
(
message_t
msg
,
char
*
indent
)
{
int
ret
,
j
;
size_t
msize
,
nparts
,
nsubparts
;
...
...
@@ -130,91 +139,123 @@ message_display_parts(message_t msg, char *indent)
size_t
nbytes
;
/* How many part those the message has? */
if
(
(
ret
=
message_get_num_parts
(
msg
,
&
nparts
)
)
!=
0
)
{
fprintf
(
stderr
,
"message_get_num_parts - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
if
((
ret
=
message_get_num_parts
(
msg
,
&
nparts
))
!=
0
)
{
fprintf
(
stderr
,
"message_get_num_parts - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
/* Iterate through all the parts.
Treat type "message/rfc822" differently, since it is a message of is own
that can have other subparts(recursive). */
for
(
j
=
1
;
j
<=
nparts
;
j
++
)
{
if
((
ret
=
message_get_part
(
msg
,
j
,
&
part
)
)
!=
0
)
{
fprintf
(
stderr
,
"mime_get_part - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
if
((
ret
=
message_size
(
part
,
&
msize
)
)
!=
0
)
{
fprintf
(
stderr
,
"message_size - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
if
((
ret
=
message_get_header
(
part
,
&
hdr
)
)
!=
0
)
{
fprintf
(
stderr
,
"message_get_header - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
header_get_value
(
hdr
,
MU_HEADER_CONTENT_TYPE
,
type
,
sizeof
(
type
),
NULL
);
printf
(
"%sType of part %d = %s
\n
"
,
indent
,
j
,
type
);
printf
(
"%sMessage part size - %d
\n
"
,
indent
,
msize
);
for
(
j
=
1
;
j
<=
nparts
;
j
++
)
{
if
((
ret
=
message_get_part
(
msg
,
j
,
&
part
))
!=
0
)
{
fprintf
(
stderr
,
"mime_get_part - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
if
((
ret
=
message_size
(
part
,
&
msize
))
!=
0
)
{
fprintf
(
stderr
,
"message_size - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
if
((
ret
=
message_get_header
(
part
,
&
hdr
))
!=
0
)
{
fprintf
(
stderr
,
"message_get_header - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
header_get_value
(
hdr
,
MU_HEADER_CONTENT_TYPE
,
type
,
sizeof
(
type
),
NULL
);
printf
(
"%sType of part %d = %s
\n
"
,
indent
,
j
,
type
);
printf
(
"%sMessage part size - %d
\n
"
,
indent
,
msize
);
encoding
[
0
]
=
'\0'
;
header_get_value
(
hdr
,
MU_HEADER_CONTENT_TRANSFER_ENCODING
,
encoding
,
sizeof
(
encoding
),
NULL
);
header_get_value
(
hdr
,
MU_HEADER_CONTENT_TRANSFER_ENCODING
,
encoding
,
sizeof
(
encoding
),
NULL
);
ismulti
=
0
;
if
(
(
type
[
0
]
&&
strncasecmp
(
type
,
"message/rfc822"
,
strlen
(
type
))
==
0
)
||
(
message_is_multipart
(
part
,
&
ismulti
)
==
0
&&
ismulti
)
)
{
if
((
type
[
0
]
&&
strncasecmp
(
type
,
"message/rfc822"
,
strlen
(
type
))
==
0
)
||
(
message_is_multipart
(
part
,
&
ismulti
)
==
0
&&
ismulti
))
{
char
tmp
[
10
];
if
(
!
ismulti
)
{
ret
=
message_unencapsulate
(
part
,
&
part
,
NULL
);
if
(
!
ismulti
)
{
ret
=
message_unencapsulate
(
part
,
&
part
,
NULL
);
if
(
ret
!=
0
)
fprintf
(
stderr
,
"message_unencapsulate - %s
\n
"
,
strerror
(
ret
));
fprintf
(
stderr
,
"message_unencapsulate - %s
\n
"
,
strerror
(
ret
));
break
;
}
if
((
ret
=
message_get_header
(
part
,
&
hdr
)
)
!=
0
)
{
fprintf
(
stderr
,
"message_get_header - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
if
((
ret
=
message_get_header
(
part
,
&
hdr
))
!=
0
)
{
fprintf
(
stderr
,
"message_get_header - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
header_get_value
(
hdr
,
MU_HEADER_FROM
,
from
,
sizeof
(
from
),
NULL
);
header_get_value
(
hdr
,
MU_HEADER_SUBJECT
,
subject
,
sizeof
(
subject
),
NULL
);
printf
(
"%sEncapsulated message : %s
\t
%s
\n
"
,
indent
,
from
,
subject
);
printf
(
"%s-------------------------------------------------------------------
\n
"
,
indent
);
if
(
(
ret
=
message_get_num_parts
(
part
,
&
nsubparts
)
)
!=
0
)
{
fprintf
(
stderr
,
"mime_get_num_parts - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
strcpy
(
tmp
,
indent
);
strcat
(
tmp
,
"
\t
"
);
message_display_parts
(
part
,
tmp
);
header_get_value
(
hdr
,
MU_HEADER_SUBJECT
,
subject
,
sizeof
(
subject
),
NULL
);
printf
(
"%sEncapsulated message : %s
\t
%s
\n
"
,
indent
,
from
,
subject
);
printf
(
"%s-------------------------------------------------------------------
\n
"
,
indent
);
if
((
ret
=
message_get_num_parts
(
part
,
&
nsubparts
))
!=
0
)
{
fprintf
(
stderr
,
"mime_get_num_parts - %s
\n
"
,
strerror
(
ret
));
exit
(
2
);
}
strcpy
(
tmp
,
indent
);
strcat
(
tmp
,
"
\t
"
);
message_display_parts
(
part
,
tmp
);
message_destroy
(
&
part
,
NULL
);
}
else
if
(
type
[
0
]
==
'\0'
||
(
strncasecmp
(
type
,
"text/plain"
,
strlen
(
"text/plain"
))
==
0
)
||
(
strncasecmp
(
type
,
"text/html"
,
strlen
(
"text/html"
))
==
0
))
{
printf
(
"%sText Message
\n
"
,
indent
);
printf
(
"%s-------------------------------------------------------------------
\n
"
,
indent
);
message_get_body
(
part
,
&
body
);
body_get_stream
(
body
,
&
str
);
filter_create
(
&
str
,
str
,
encoding
,
0
,
0
);
else
if
(
type
[
0
]
==
'\0'
||
(
strncasecmp
(
type
,
"text/plain"
,
strlen
(
"text/plain"
))
==
0
)
||
(
strncasecmp
(
type
,
"text/html"
,
strlen
(
"text/html"
))
==
0
))
{
printf
(
"%sText Message
\n
"
,
indent
);
printf
(
"%s-------------------------------------------------------------------
\n
"
,
indent
);
message_get_body
(
part
,
&
body
);
body_get_stream
(
body
,
&
str
);
filter_create
(
&
str
,
str
,
encoding
,
0
,
0
);
offset
=
0
;
while
(
stream_readline
(
str
,
buf
,
sizeof
(
buf
),
offset
,
&
nbytes
)
==
0
&&
nbytes
)
{
printf
(
"%s%s"
,
indent
,
buf
);
while
(
stream_readline
(
str
,
buf
,
sizeof
(
buf
),
offset
,
&
nbytes
)
==
0
&&
nbytes
)
{
printf
(
"%s%s"
,
indent
,
buf
);
offset
+=
nbytes
;
}
stream_destroy
(
&
str
,
NULL
);
stream_destroy
(
&
str
,
NULL
);
}
else
{
else
{
#if 1
/* Save the attachements. */
char
*
fname
;
message_attachment_filename
(
part
,
&
fname
);
if
(
fname
==
NULL
)
{
char
buffer
[
PATH_MAX
+
1
];
fname
=
tempnam
(
getcwd
(
buffer
,
PATH_MAX
),
"msg-"
);
message_attachment_filename
(
part
,
&
fname
);
if
(
fname
==
NULL
)
{
char
buffer
[
PATH_MAX
+
1
];
fname
=
tempnam
(
getcwd
(
buffer
,
PATH_MAX
),
"msg-"
);
}
printf
(
"%sAttachment - saving [%s]
\n
"
,
indent
,
fname
);
printf
(
"%s-------------------------------------------------------------------
\n
"
,
indent
);
printf
(
"%sAttachment - saving [%s]
\n
"
,
indent
,
fname
);
printf
(
"%s-------------------------------------------------------------------
\n
"
,
indent
);
/* FIXME: Somethings is not quite correct with this function.
Please fix. */
message_save_attachment
(
part
,
fname
,
NULL
);
free
(
fname
);
message_save_attachment
(
part
,
fname
,
NULL
);
free
(
fname
);
#endif
}
printf
(
"
\n
%s End -------------------------------------------------------------------
\n
"
,
indent
);
printf
(
"
\n
%s End -------------------------------------------------------------------
\n
"
,
indent
);
}
}
...
...
mailbox/attachment.c
View file @
e939545
This diff is collapsed.
Click to expand it.
Please
register
or
sign in
to post a comment