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
953d5e9e
...
953d5e9e0921167f53d25b85c94421b39c6991c7
authored
1999-10-09 01:13:07 +0000
by
Sean 'Shaleh' Perry
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added showmail
more mailbox cleanups
1 parent
36d9df9d
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
27 deletions
ChangeLog
examples/Makefile
examples/from.c
examples/showmail.c
libmailbox/mailbox.c
libmailbox/unixmbox.c
ChangeLog
View file @
953d5e9
Sean 'Shaleh' Perry <shaleh@debian.org> Fri, 8 Oct 1999 18:13:45 -0700
* added showmail.c to examples
* libmailbox: some minor code cleanups
Sean 'Shaleh' Perry <shaleh@debian.org> Fri, 8 Oct 1999 01:08:42 -0700
* fixed the "if empty mailbox, return not implemented"
...
...
examples/Makefile
View file @
953d5e9
...
...
@@ -5,5 +5,8 @@ LIBS = ../libmailbox/.libs/libmailbox.al
from
:
from.c $(LIBS)
gcc
$(CFLAGS)
$(INCLUDES)
-o from from.c
$(LIBS)
showmail
:
showmail.c $(LIBS)
gcc
$(CFLAGS)
$(INCLUDES)
-o showmail showmail.c
$(LIBS)
clean
:
rm -f from
rm -f from
showmail
...
...
examples/from.c
View file @
953d5e9
...
...
@@ -44,7 +44,7 @@ int main(int argc, char *argv[]) {
perror
(
"mbox_header_line"
);
exit
(
-
1
);
}
date
=
mbox_header_line
(
mail
,
i
,
"
Date
"
);
date
=
mbox_header_line
(
mail
,
i
,
"
Received
"
);
if
(
date
==
NULL
)
{
perror
(
"mbox_header_line"
);
...
...
examples/showmail.c
0 → 100644
View file @
953d5e9
#include "mailbox.h"
#include <paths.h>
int
main
(
int
argc
,
char
*
argv
[])
{
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
);
}
libmailbox/mailbox.c
View file @
953d5e9
...
...
@@ -26,6 +26,7 @@
#include <errno.h>
#endif
#include <ctype.h>
#include <sys/stat.h>
#include <unistd.h>
...
...
@@ -83,19 +84,7 @@ mbox_open (const char *name)
mbox
->
_get_body
=
_mbox_dummy4
;
mbox
->
_get_header
=
_mbox_dummy4
;
if
(
S_ISDIR
(
st
.
st_mode
))
{
/* for example...
if (maildir_open (mbox, name) == 1)
return mbox;
else if (errno != 0)
return NULL;
else
errno = 0;
*/
errno
=
ENOSYS
;
}
else
if
(
S_ISREG
(
st
.
st_mode
))
if
(
S_ISREG
(
st
.
st_mode
))
{
if
(
unixmbox_open
(
mbox
)
==
0
)
return
mbox
;
...
...
@@ -110,6 +99,14 @@ mbox_open (const char *name)
errno
=
ENOSYS
;
/* no other mailboxes supported right now */
}
}
else
if
(
S_ISDIR
(
st
.
st_mode
))
{
/* for example...
if (maildir_open (mbox, name) == 1)
return mbox;
*/
errno
=
ENOSYS
;
}
else
errno
=
EINVAL
;
/* neither directory nor file, so bomb */
...
...
@@ -125,8 +122,9 @@ char *
mbox_header_line
(
mailbox
*
mbox
,
unsigned
int
num
,
const
char
*
header
)
{
char
*
full
,
*
tmp
,
*
line
;
int
i
=
0
,
j
=
0
,
try
=
1
;
unsigned
int
len
,
lh
;
int
try
=
1
;
size_t
i
=
0
,
j
=
0
;
size_t
len
,
lh
;
if
(
mbox
==
NULL
||
header
==
NULL
)
{
...
...
@@ -143,21 +141,19 @@ mbox_header_line (mailbox *mbox, unsigned int num, const char *header)
tmp
=
NULL
;
/* First get the appropriate line at the beginning */
/* FIXME: hmm len - (lh + 2) *COULD* be negative, but should never be */
for
(
i
=
0
;
i
<
len
-
(
lh
+
2
);
i
++
)
{
if
(
try
==
1
)
{
if
(
!
strncasecmp
(
&
full
[
i
],
header
,
lh
)
&&
full
[
i
+
lh
]
==
':'
)
{
full
[
len
-
i
]
=
'\0'
;
tmp
=
strdup
(
&
full
[
i
+
lh
+
2
]);
if
(
tmp
==
NULL
)
{
free
(
full
);
return
NULL
;
}
i
=
len
;
break
;
}
else
try
=
0
;
...
...
@@ -178,7 +174,7 @@ mbox_header_line (mailbox *mbox, unsigned int num, const char *header)
len
=
strlen
(
tmp
);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
tmp
[
i
]
==
'\n'
&&
i
<
(
len
-
1
)
&&
(
tmp
[
i
+
1
]
==
' '
||
tmp
[
i
+
1
]
==
'\t'
))
if
(
tmp
[
i
]
==
'\n'
&&
i
<
(
len
-
1
)
&&
isspace
(
tmp
[
i
+
1
]
))
{
if
(
tmp
[
i
+
1
]
==
'\t'
)
tmp
[
i
+
1
]
=
' '
;
...
...
@@ -188,7 +184,7 @@ mbox_header_line (mailbox *mbox, unsigned int num, const char *header)
else
if
(
tmp
[
i
]
==
'\n'
)
{
tmp
[
i
]
=
'\0'
;
i
=
len
;
break
;
}
}
line
=
strdup
(
tmp
);
...
...
@@ -225,7 +221,7 @@ mbox_body_lines (mailbox *mbox, unsigned int num, unsigned int lines)
{
full
[
i
+
1
]
=
'\0'
;
buf
=
strdup
(
full
);
i
=
len
;
break
;
}
}
}
...
...
libmailbox/unixmbox.c
View file @
953d5e9
...
...
@@ -330,8 +330,16 @@ unixmbox_get_body (mailbox * mbox, unsigned int num)
}
memset
(
buf
,
0
,
size
+
1
);
fsetpos
(
data
->
file
,
&
(
data
->
messages
[
num
].
body
));
fread
(
buf
,
size
,
sizeof
(
char
),
data
->
file
);
if
(
fsetpos
(
data
->
file
,
&
(
data
->
messages
[
num
].
body
))
==
-
1
)
{
free
(
buf
);
return
NULL
;
}
if
(
fread
(
buf
,
sizeof
(
char
),
size
,
data
->
file
)
<
size
)
{
free
(
buf
);
return
NULL
;
}
return
buf
;
}
...
...
@@ -368,8 +376,16 @@ unixmbox_get_header (mailbox * mbox, unsigned int num)
memset
(
buf
,
0
,
size
+
1
);
fsetpos
(
data
->
file
,
&
(
data
->
messages
[
num
].
header
));
fread
(
buf
,
size
,
sizeof
(
char
),
data
->
file
);
if
(
fsetpos
(
data
->
file
,
&
(
data
->
messages
[
num
].
header
))
==
-
1
)
{
free
(
buf
);
return
NULL
;
}
if
(
fread
(
buf
,
sizeof
(
char
),
size
,
data
->
file
)
<
size
)
{
free
(
buf
);
return
NULL
;
}
return
buf
;
}
...
...
Please
register
or
sign in
to post a comment