static char *SccsId
= "@(#)fio.c 2.6 %G%";
* Set up the input pointers while copying the mail file into
register int count
, s
, l
;
int maybe
, mestmp
, flag
, inhead
;
if ((mestmp
= opentemp(tempSet
)) < 0)
while (c
!= EOF
&& c
!= '\n') {
if (cp
- linebuf
>= LINESIZE
- 1) {
if (cp
== linebuf
&& c
== EOF
) {
this.m_offset
= offsetof(offset
);
this.m_block
= blockof(offset
);
if (append(&this, mestmp
)) {
count
= cp
- linebuf
+ 1;
if (maybe
&& linebuf
[0] == 'F' && ishead(linebuf
)) {
this.m_block
= blockof(offset
);
this.m_offset
= offsetof(offset
);
if (append(&this, mestmp
)) {
if (inhead
&& index(linebuf
, ':')) {
if (icequal(wbuf
, "status")) {
cp
= index(linebuf
, ':');
* Drop the passed line onto the passed output buffer.
* If a write error occurs, return -1, else the count of
* characters written, including the newline.
* Quickly read a line from the specified input into the line
* buffer; return characters read.
while (c
!= '\n' && c
!= EOF
) {
if (cp
- linebuf
>= BUFSIZ
-1) {
return(cp
- linebuf
+ 1);
if (c
== EOF
&& cp
== linebuf
)
return(cp
- linebuf
+ 1);
* Read up a line from the specified input into the line
* buffer. Return the number of characters read. Do not
* include the newline at the end.
for (cp
= linebuf
; c
!= '\n' && c
!= EOF
; c
= getc(ibuf
)) {
if (cp
- linebuf
< LINESIZE
-2)
} while (ferror(ibuf
) && ibuf
== stdin
);
if (c
== EOF
&& cp
== linebuf
)
return(cp
- linebuf
+ 1);
* Return a file buffer all ready to read up the
* passed message pointer.
register struct message
*mp
;
if (fseek(itf
, off
, 0) < 0) {
panic("temporary file seek");
* Take the data out of the passed ghost file and toss it into
* a dynamically allocated message structure.
register struct message
*m
;
mp
= calloc((unsigned) (msgCount
+ 1), sizeof *m
);
printf("Insufficient memory for %d messages\n", msgCount
);
if (message
!= (struct message
*) 0)
message
= (struct message
*) mp
;
while (count
= read(f
, mp
, BUFSIZ
))
for (m
= &message
[0]; m
< &message
[msgCount
]; m
++) {
m
->m_size
= (m
+1)->m_size
;
m
->m_lines
= (m
+1)->m_lines
;
m
->m_flag
= (m
+1)->m_flag
;
message
[msgCount
].m_size
= 0;
message
[msgCount
].m_lines
= 0;
* Append the passed message descriptor onto the temp file.
* If the write fails, return 1, else 0
if (write(f
, (char *) mp
, sizeof *mp
) != sizeof *mp
)
* Delete a file, but only if the file is a plain file.
if (stat(name
, &statb
) < 0)
if ((statb
.st_mode
& S_IFMT
) != S_IFREG
) {
* Terminate an editing session by attempting to write out the user's
* file from the temporary. Save any new stuff appended to the file.
register struct message
*mp
;
FILE *obuf
, *ibuf
, *readstat
;
if ((readstat
= fopen(Tflag
, "w")) == NULL
)
for (mp
= &message
[0], gotcha
= 0; mp
< &message
[msgCount
]; mp
++) {
if (mp
->m_flag
& (MODIFY
|MDELETED
|MSTATUS
))
if (Tflag
!= NOSTR
&& (mp
->m_flag
& (MREAD
|MDELETED
)) != 0) {
if ((id
= hfield("article-id", mp
)) != NOSTR
)
fprintf(readstat
, "%s\n", id
);
if (!gotcha
|| Tflag
!= NOSTR
)
if (stat(editfile
, &statb
) >= 0 && statb
.st_size
> mailsize
) {
strcpy(tempname
, "/tmp/mboxXXXXXX");
if ((obuf
= fopen(tempname
, "w")) == NULL
) {
if ((ibuf
= fopen(editfile
, "r")) == NULL
) {
fseek(ibuf
, mailsize
, 0);
while ((c
= getc(ibuf
)) != EOF
)
if ((ibuf
= fopen(tempname
, "r")) == NULL
) {
printf("\"%s\" ", editfile
);
if ((obuf
= fopen(editfile
, "w")) == NULL
) {
for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++) {
if ((mp
->m_flag
& MDELETED
) != 0)
if (send(mp
, obuf
) < 0) {
gotcha
= (c
== 0 && ibuf
== NULL
);
while ((c
= getc(ibuf
)) != EOF
)
* Hold signals SIGHUP - SIGQUIT.
for (i
= SIGHUP
; i
<= SIGQUIT
; i
++)
* Release signals SIGHUP - SIGQUIT
for (i
= SIGHUP
; i
<= SIGQUIT
; i
++)
* Empty the output buffer.
* Open a temp file by creating, closing, unlinking, and
* reopening. Return the open file descriptor.
if ((f
= creat(file
, 0600)) < 0) {
if ((f
= open(file
, 2)) < 0) {
* Flush the standard output.
* Determine the size of the file possessed by
* Take a file name, possibly with shell meta characters
* in it and expand it by using "sh -c echo filename"
* Return the file name as a dynamic string.
register char *cp
, *Shell
;
int s
, pivec
[2], (*sigint
)();
if (name
[0] == '+' && (cp
= value("maildir")) != 0) {
sprintf(xname
, "%s/%s", cp
, name
+ 1);
sprintf(xname
, "%s/%s/%s", homedir
, cp
, name
+ 1);
return(expand(savestr(xname
)));
if (!anyof(name
, "~{[*?$`'\"\\"))
sprintf(cmdbuf
, "echo %s", name
);
if ((pid
= vfork()) == 0) {
execl(Shell
, Shell
, "-c", cmdbuf
, 0);
l
= read(pivec
[0], xname
, BUFSIZ
);
if (s
!= 0 && s
!= SIGPIPE
) {
fprintf(stderr
, "\"Echo\" failed\n");
fprintf(stderr
, "\"%s\": No match\n", name
);
fprintf(stderr
, "Buffer overflow expanding \"%s\"\n", name
);
for (cp
= &xname
[l
-1]; *cp
== '\n' && cp
> xname
; cp
--)
if (any(' ', xname
) && stat(xname
, &sbuf
) < 0) {
fprintf(stderr
, "\"%s\": Ambiguous\n", name
);
* A nicer version of Fdopen, which allows us to fclose
* without losing the open file.