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
c4ad70fc
...
c4ad70fcc49fe4d186b97d18de5044c1b2791853
authored
2003-01-16 16:18:20 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Handle draft file. Added --use option.
1 parent
4a489905
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
14 deletions
mh/repl.c
mh/repl.c
View file @
c4ad70f
...
...
@@ -18,6 +18,8 @@
/* MH reply command */
#include <mh.h>
#include <sys/stat.h>
#include <unistd.h>
const
char
*
argp_program_version
=
"reply ("
PACKAGE_STRING
")"
;
static
char
doc
[]
=
"GNU MH reply"
;
...
...
@@ -62,6 +64,7 @@ static struct argp_option options[] = {
{
"width"
,
'w'
,
N_
(
"NUMBER"
),
0
,
N_
(
"Set output width"
)},
{
"whatnowproc"
,
ARG_WHATNOWPROC
,
N_
(
"PROG"
),
0
,
N_
(
"Set the replacement for whatnow program"
)},
{
"use"
,
'u'
,
NULL
,
0
,
N_
(
"Use draft file preserved after the last session"
)
},
{
N_
(
"
\n
Use -help switch to obtain the list of traditional MH options. "
),
0
,
0
,
OPTION_DOC
,
""
},
{
0
}
};
...
...
@@ -108,6 +111,7 @@ static mh_msgset_t msgset;
static
mailbox_t
mbox
;
static
int
build_only
=
0
;
/* --build flag */
static
int
query_mode
=
0
;
/* --query flag */
static
int
use_draft
=
0
;
/* --use flag */
static
int
decode_cc_flag
(
const
char
*
opt
,
const
char
*
arg
)
...
...
@@ -163,6 +167,10 @@ opt_handler (int key, char *arg, void *unused)
case
'm'
:
wh_env
.
draftmessage
=
arg
;
break
;
case
'u'
:
use_draft
++
;
break
;
case
'w'
:
width
=
strtoul
(
arg
,
NULL
,
0
);
...
...
@@ -204,18 +212,37 @@ make_draft ()
{
int
rc
;
message_t
msg
;
FILE
*
fp
;
char
buffer
[
1024
];
#define bufsize sizeof(buffer)
int
disp
=
DISP_REPLACE
;
struct
stat
st
;
/* First check if the draft exists */
if
(
stat
(
wh_env
.
draftfile
,
&
st
)
==
0
)
{
if
(
use_draft
)
disp
=
DISP_USE
;
else
{
printf
(
_
(
"Draft
\"
%s
\"
exists (%lu bytes).
\n
"
),
wh_env
.
draftfile
,
(
unsigned
long
)
st
.
st_size
);
disp
=
mh_disposition
(
wh_env
.
draftfile
);
}
}
/* FIXME: first check if the draft exists */
fp
=
fopen
(
wh_env
.
file
,
"w+"
);
if
(
!
fp
)
switch
(
disp
)
{
mh_error
(
_
(
"cannot open draft file %s: %s"
),
wh_env
.
file
,
strerror
(
errno
));
exit
(
1
);
case
DISP_QUIT
:
exit
(
0
);
case
DISP_USE
:
unlink
(
wh_env
.
file
);
rename
(
wh_env
.
draftfile
,
wh_env
.
file
);
break
;
case
DISP_REPLACE
:
unlink
(
wh_env
.
draftfile
);
break
;
}
rc
=
mailbox_get_message
(
mbox
,
msgset
.
list
[
0
],
&
msg
);
if
(
rc
)
...
...
@@ -225,10 +252,23 @@ make_draft ()
mu_errstring
(
rc
));
exit
(
1
);
}
mh_format
(
&
format
,
msg
,
msgset
.
list
[
0
],
buffer
,
bufsize
);
fprintf
(
fp
,
"%s"
,
buffer
);
fclose
(
fp
);
if
(
disp
==
DISP_REPLACE
)
{
FILE
*
fp
=
fopen
(
wh_env
.
file
,
"w+"
);
char
buffer
[
1024
];
#define bufsize sizeof(buffer)
if
(
!
fp
)
{
mh_error
(
_
(
"cannot open draft file %s: %s"
),
wh_env
.
file
,
strerror
(
errno
));
exit
(
1
);
}
mh_format
(
&
format
,
msg
,
msgset
.
list
[
0
],
buffer
,
bufsize
);
fprintf
(
fp
,
"%s"
,
buffer
);
fclose
(
fp
);
}
{
url_t
url
;
...
...
@@ -278,7 +318,8 @@ main (int argc, char **argv)
}
wh_env
.
file
=
mh_expand_name
(
wh_env
.
draftfolder
,
"reply"
,
0
);
wh_env
.
draftfile
=
mh_expand_name
(
wh_env
.
draftfolder
,
"draft"
,
0
);
make_draft
();
/* Exit immediately if --build is given */
...
...
Please
register
or
sign in
to post a comment