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
e7bbc45a
...
e7bbc45a75826f99a0fcc426197a6c90ef6c398f
authored
2001-01-13 08:23:51 +0000
by
Jakob Kaivo
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
work on mail sending capability, now `mail -s"foo bar" baz@quux` is close to
doing the right thing
1 parent
2568cfa5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
63 deletions
mail/mail.c
mail/send.c
mail/source.c
mail/mail.c
View file @
e7bbc45
...
...
@@ -103,6 +103,13 @@ parse_opt (int key, char *arg, struct argp_state *state)
case
'F'
:
util_do_command
(
"set byname"
);
break
;
case
ARGP_KEY_ARG
:
args
->
args
=
realloc
(
args
->
args
,
sizeof
(
char
*
)
*
(
state
->
arg_num
+
2
));
args
->
args
[
state
->
arg_num
]
=
arg
;
args
->
args
[
state
->
arg_num
+
1
]
=
NULL
;
util_do_command
(
"set mode=send"
);
break
;
default:
return
ARGP_ERR_UNKNOWN
;
}
...
...
@@ -193,6 +200,7 @@ main (int argc, char **argv)
util_do_command
(
"set rc"
);
util_do_command
(
"set noquit"
);
args
.
args
=
NULL
;
args
.
file
=
NULL
;
args
.
user
=
NULL
;
...
...
@@ -203,30 +211,13 @@ main (int argc, char **argv)
if
((
util_find_env
(
"rc"
))
->
set
)
util_do_command
(
"source %s"
,
getenv
(
"MAILRC"
));
/* Initialize readline */
rl_readline_name
=
"mail"
;
rl_attempted_completion_function
=
(
CPPFunction
*
)
util_command_completion
;
/* open the mailbox */
if
(
args
.
file
==
NULL
)
{
if
(
mailbox_create_default
(
&
mbox
,
args
.
user
)
!=
0
)
exit
(
EXIT_FAILURE
);
}
else
if
(
mailbox_create
(
&
mbox
,
args
.
file
)
!=
0
)
exit
(
EXIT_FAILURE
);
if
(
mailbox_open
(
mbox
,
MU_STREAM_READ
)
!=
0
)
exit
(
EXIT_FAILURE
);
if
(
mailbox_messages_count
(
mbox
,
&
total
)
!=
0
)
exit
(
EXIT_FAILURE
);
/* how should we be running? */
if
((
mode
=
util_find_env
(
"mode"
))
==
NULL
||
mode
->
set
==
0
)
exit
(
EXIT_FAILURE
);
modelen
=
strlen
(
mode
->
value
);
if
(
!
(
util_find_env
(
"quit"
))
->
set
)
/* Interactive mode */
if
(
!
(
util_find_env
(
"quiet"
))
->
set
)
{
printf
(
"%s, Copyright (C) 2001 Free Software Foundation, Inc.
\n
"
"mail comes with ABSOLUTELY NO WARRANTY; for details type
\n
"
...
...
@@ -235,49 +226,81 @@ main (int argc, char **argv)
"for details.
\n
"
,
argp_program_version
);
}
modelen
=
strlen
(
mode
->
value
);
if
(
strlen
(
"exist"
)
==
modelen
&&
!
strcmp
(
"exist"
,
mode
->
value
))
return
(
total
<
1
)
?
1
:
0
;
else
if
(
strlen
(
"print"
)
==
modelen
&&
!
strcmp
(
"print"
,
mode
->
value
))
return
util_do_command
(
"print *"
);
else
if
(
strlen
(
"headers"
)
==
modelen
&&
!
strcmp
(
"headers"
,
mode
->
value
))
return
util_do_command
(
"from *"
);
else
if
(
strlen
(
"send"
)
==
modelen
&&
!
strcmp
(
"send"
,
mode
->
value
))
/* Mode is just sending */
if
(
strlen
(
"send"
)
==
modelen
&&
!
strcmp
(
"send"
,
mode
->
value
))
{
/* FIXME: set cmd to "mail [add1...]" */
cmd
=
strdup
(
"mail"
);
return
util_do_command
(
cmd
);
char
*
buf
=
NULL
;
int
num
=
0
;
if
(
args
.
args
!=
NULL
)
while
(
args
.
args
[
num
]
!=
NULL
)
num
++
;
argcv_string
(
num
,
args
.
args
,
&
buf
);
return
util_do_command
(
"mail %s"
,
buf
);
}
/* initial commands */
if
((
util_find_env
(
"header"
))
->
set
)
util_do_command
(
"from *"
);
prompt
=
util_find_env
(
"prompt"
);
while
(
1
)
/* Or acting as a normal reader */
else
{
int
len
;
if
(
command
)
free
(
command
);
command
=
readline
(
prompt
->
set
&&
prompt
->
value
!=
NULL
?
prompt
->
value
:
" "
);
len
=
strlen
(
command
);
while
(
command
[
len
-
1
]
==
'\\'
)
{
char
*
buf
;
char
*
command2
=
readline
(
"> "
);
/* Initialize readline */
rl_readline_name
=
"mail"
;
rl_attempted_completion_function
=
(
CPPFunction
*
)
util_command_completion
;
command
[
len
-
1
]
=
'\0'
;
buf
=
malloc
((
len
+
strlen
(
command2
))
*
sizeof
(
char
));
strcpy
(
buf
,
command
);
strcat
(
buf
,
command2
);
free
(
command
);
command
=
buf
;
/* open the mailbox */
if
(
args
.
file
==
NULL
)
{
if
(
mailbox_create_default
(
&
mbox
,
args
.
user
)
!=
0
)
exit
(
EXIT_FAILURE
);
}
else
if
(
mailbox_create
(
&
mbox
,
args
.
file
)
!=
0
)
exit
(
EXIT_FAILURE
);
if
(
mailbox_open
(
mbox
,
MU_STREAM_READ
)
!=
0
)
exit
(
EXIT_FAILURE
);
if
(
mailbox_messages_count
(
mbox
,
&
total
)
!=
0
)
exit
(
EXIT_FAILURE
);
if
(
strlen
(
"exist"
)
==
modelen
&&
!
strcmp
(
"exist"
,
mode
->
value
))
return
(
total
<
1
)
?
1
:
0
;
else
if
(
strlen
(
"print"
)
==
modelen
&&
!
strcmp
(
"print"
,
mode
->
value
))
return
util_do_command
(
"print *"
);
else
if
(
strlen
(
"headers"
)
==
modelen
&&
!
strcmp
(
"headers"
,
mode
->
value
))
return
util_do_command
(
"from *"
);
/* initial commands */
if
((
util_find_env
(
"header"
))
->
set
)
util_do_command
(
"from *"
);
prompt
=
util_find_env
(
"prompt"
);
while
(
1
)
{
int
len
;
if
(
command
)
free
(
command
);
command
=
readline
(
prompt
->
set
&&
prompt
->
value
!=
NULL
?
prompt
->
value
:
"? "
);
len
=
strlen
(
command
);
while
(
command
[
len
-
1
]
==
'\\'
)
{
char
*
buf
;
char
*
command2
=
readline
(
"> "
);
command
[
len
-
1
]
=
'\0'
;
buf
=
malloc
((
len
+
strlen
(
command2
))
*
sizeof
(
char
));
strcpy
(
buf
,
command
);
strcat
(
buf
,
command2
);
free
(
command
);
command
=
buf
;
len
=
strlen
(
command
);
}
cmd
=
util_stripwhite
(
command
);
util_do_command
(
cmd
);
add_history
(
cmd
);
}
cmd
=
util_stripwhite
(
command
);
util_do_command
(
cmd
);
add_history
(
cmd
);
}
/* We should never reach this point */
return
1
;
}
...
...
mail/send.c
View file @
e7bbc45
...
...
@@ -29,6 +29,7 @@ mail_send (int argc, char **argv)
FILE
*
file
=
fopen
(
filename
,
"w"
);
char
*
buf
=
NULL
;
size_t
n
;
int
done
=
0
;
if
(
argc
<
2
)
to
=
readline
(
"To: "
);
...
...
@@ -47,7 +48,7 @@ mail_send (int argc, char **argv)
else
subj
=
(
util_find_env
(
"subject"
))
->
value
;
while
(
getline
(
&
buf
,
&
n
,
stdin
)
!=
-
1
)
while
(
getline
(
&
buf
,
&
n
,
stdin
)
>=
0
&&
!
done
)
{
if
(
buf
[
0
]
==
(
util_find_env
(
"escape"
))
->
value
[
0
])
{
...
...
@@ -57,14 +58,14 @@ mail_send (int argc, char **argv)
switch
(
buf
[
1
])
{
case
'!'
:
util_do_command
(
"!%s"
,
&
buf
[
3
]);
util_do_command
(
"!%s"
,
&
buf
[
2
]);
break
;
case
'.'
:
/* eof */
done
=
1
;
break
;
case
':'
:
case
'-'
:
util_do_command
(
"%s"
,
&
buf
[
3
]);
util_do_command
(
"%s"
,
&
buf
[
2
]);
break
;
case
'?'
:
/* escape help */
...
...
@@ -182,7 +183,19 @@ mail_send (int argc, char **argv)
/* free (buf); */
}
/* read in filename, send it */
file
=
fopen
(
filename
,
"r"
);
if
(
file
!=
NULL
)
{
/* FIXME: create a mailer here */
while
(
getline
(
&
buf
,
&
n
,
file
)
>=
0
)
{
printf
(
"%s"
,
buf
);
free
(
buf
);
buf
=
NULL
;
}
fclose
(
file
);
return
0
;
}
return
1
;
}
...
...
mail/source.c
View file @
e7bbc45
...
...
@@ -39,7 +39,6 @@ mail_source (int argc, char **argv)
util_do_command
(
"%s"
,
buf
);
free
(
buf
);
buf
=
NULL
;
s
=
0
;
}
fclose
(
rc
);
return
0
;
...
...
Please
register
or
sign in
to post a comment