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
77037aee
...
77037aee35b3e0cb54b60fce9c680b6fbfb4eb8c
authored
2001-06-15 00:06:34 +0000
by
Sam Roberts
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
GNU indented.
1 parent
ea610306
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
67 deletions
examples/mbox-dates.c
examples/showmail.c
examples/mbox-dates.c
View file @
77037ae
...
...
@@ -16,24 +16,29 @@
#include <mailutils/parse822.h>
static
const
char
*
UserAgent
(
header_t
hdr
)
static
const
char
*
UserAgent
(
header_t
hdr
)
{
static
char
agent
[
128
];
size_t
sz
;
if
(
header_get_value
(
hdr
,
"User-Agent"
,
agent
,
sizeof
(
agent
),
&
sz
)
==
0
&&
sz
!=
0
)
if
(
header_get_value
(
hdr
,
"User-Agent"
,
agent
,
sizeof
(
agent
),
&
sz
)
==
0
&&
sz
!=
0
)
return
agent
;
if
(
header_get_value
(
hdr
,
"X-Mailer"
,
agent
,
sizeof
(
agent
),
&
sz
)
==
0
&&
sz
!=
0
)
if
(
header_get_value
(
hdr
,
"X-Mailer"
,
agent
,
sizeof
(
agent
),
&
sz
)
==
0
&&
sz
!=
0
)
return
agent
;
if
(
header_get_value
(
hdr
,
"Message-Id"
,
agent
,
sizeof
(
agent
),
&
sz
)
==
0
&&
sz
!=
0
)
if
(
header_get_value
(
hdr
,
"Message-Id"
,
agent
,
sizeof
(
agent
),
&
sz
)
==
0
&&
sz
!=
0
)
return
agent
;
return
"unknown"
;
}
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
mailbox_t
mbox
;
size_t
i
;
...
...
@@ -41,7 +46,7 @@ main(int argc, char **argv)
char
*
mboxname
=
argv
[
1
];
int
status
;
/* Register
the desire formats.
*/
/* Register
desired mailbox formats.
*/
{
list_t
bookie
;
registrar_get_list
(
&
bookie
);
...
...
@@ -49,11 +54,11 @@ main(int argc, char **argv)
}
if
((
status
=
mailbox_create_default
(
&
mbox
,
mboxname
))
!=
0
)
{
fprintf
(
stderr
,
"could not create <%s>: %s
\n
"
,
mboxname
,
strerror
(
status
));
exit
(
1
);
}
{
fprintf
(
stderr
,
"could not create <%s>: %s
\n
"
,
mboxname
,
strerror
(
status
));
exit
(
1
);
}
{
debug_t
debug
;
...
...
@@ -62,56 +67,50 @@ main(int argc, char **argv)
}
if
((
status
=
mailbox_open
(
mbox
,
MU_STREAM_READ
))
!=
0
)
{
fprintf
(
stderr
,
"could not open mbox: %s
\n
"
,
strerror
(
status
));
exit
(
1
);
}
{
fprintf
(
stderr
,
"could not open mbox: %s
\n
"
,
strerror
(
status
));
exit
(
1
);
}
mailbox_messages_count
(
mbox
,
&
count
);
for
(
i
=
1
;
i
<=
count
;
++
i
)
{
message_t
msg
;
header_t
hdr
;
char
mailer
[
128
];
char
date
[
128
];
size_t
len
=
0
;
if
(
(
status
=
mailbox_get_message
(
mbox
,
i
,
&
msg
))
!=
0
||
(
status
=
message_get_header
(
msg
,
&
hdr
))
!=
0
)
{
printf
(
"%s, msg %d: %s
\n
"
,
mboxname
,
i
,
strerror
(
status
));
continue
;
}
if
((
status
=
header_get_value
(
hdr
,
MU_HEADER_DATE
,
date
,
sizeof
(
date
),
&
len
))
!=
0
)
{
printf
(
"%s, msg %d: NO DATE (mua? %s)
\n
"
,
mboxname
,
i
,
UserAgent
(
hdr
));
continue
;
message_t
msg
;
header_t
hdr
;
char
date
[
128
];
size_t
len
=
0
;
if
((
status
=
mailbox_get_message
(
mbox
,
i
,
&
msg
))
!=
0
||
(
status
=
message_get_header
(
msg
,
&
hdr
))
!=
0
)
{
printf
(
"%s, msg %d: %s
\n
"
,
mboxname
,
i
,
strerror
(
status
));
continue
;
}
if
((
status
=
header_get_value
(
hdr
,
MU_HEADER_DATE
,
date
,
sizeof
(
date
),
&
len
))
!=
0
)
{
printf
(
"%s, msg %d: NO DATE (mua? %s)
\n
"
,
mboxname
,
i
,
UserAgent
(
hdr
));
continue
;
}
else
{
const
char
*
s
=
date
;
struct
tm
tm
;
if
(
parse822_date_time
(
&
s
,
s
+
strlen
(
s
),
&
tm
))
{
printf
(
"%s, msg %d: BAD DATE <%s> (mua? %s)
\n
"
,
mboxname
,
i
,
date
,
UserAgent
(
hdr
));
continue
;
}
}
}
else
{
const
char
*
s
=
date
;
struct
tm
tm
;
char
dir
[]
=
"yyyy.mm.dd"
;
size_t
nparts
=
0
;
size_t
partno
;
if
(
parse822_date_time
(
&
s
,
s
+
strlen
(
s
),
&
tm
))
{
printf
(
"%s, msg %d: BAD DATE <%s> (mua? %s)
\n
"
,
mboxname
,
i
,
date
,
UserAgent
(
hdr
));
continue
;
}
}
}
mailbox_close
(
mbox
);
mailbox_destroy
(
&
mbox
);
return
status
;
}
...
...
examples/showmail.c
View file @
77037ae
#include "mailbox.h"
#include <paths.h>
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
mailbox
*
mbox
;
char
*
user
;
char
*
body
;
char
mailpath
[
256
];
int
i
;
mailbox
*
mbox
;
char
*
user
;
char
*
body
;
char
mailpath
[
256
];
int
i
;
user
=
getenv
(
"USER"
);
snprintf
(
mailpath
,
256
,
"%s/%s"
,
_PATH_MAILDIR
,
user
);
mbox
=
mbox_open
(
mailpath
);
for
(
i
=
0
;
i
<
mbox
->
messages
;
++
i
)
{
body
=
mbox_get_body
(
mbox
,
i
);
printf
(
"%s
\n
"
,
body
);
}
mbox_close
(
mbox
);
user
=
getenv
(
"USER"
);
snprintf
(
mailpath
,
256
,
"%s/%s"
,
_PATH_MAILDIR
,
user
);
mbox
=
mbox_open
(
mailpath
);
for
(
i
=
0
;
i
<
mbox
->
messages
;
++
i
)
{
body
=
mbox_get_body
(
mbox
,
i
);
printf
(
"%s
\n
"
,
body
);
}
mbox_close
(
mbox
);
}
...
...
Please
register
or
sign in
to post a comment