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
6657a825
...
6657a825bf2f7f1ead25bae53a1d733c3b2f0db3
authored
2001-09-17 14:13:46 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
New globals: current_folder, current_message, mh_list_format, etc.
1 parent
d775d8e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
1 deletions
mh/mh_init.c
mh/mh_init.c
View file @
6657a82
...
...
@@ -19,11 +19,28 @@
#include <mh.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
char
*
current_folder
=
"inbox"
;
size_t
current_message
;
char
mh_list_format
[]
=
"%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>"
"%02(mon{date})/%02(mday{date})"
"%<{date} %|*%>"
"%<(mymbox{from})%<{to}To:%14(friendly{to})%>%>"
"%<(zero)%17(friendly{from})%>"
" %{subject}%<{body}<<%{body}>>%>"
;
void
mh_init
()
{
list_t
bookie
;
char
*
ctx_name
;
header_t
header
=
NULL
;
/* Register mailbox formats */
registrar_get_list
(
&
bookie
);
list_append
(
bookie
,
mh_record
);
list_append
(
bookie
,
mbox_record
);
...
...
@@ -33,8 +50,108 @@ mh_init ()
/* Possible supported mailers. */
list_append
(
bookie
,
sendmail_record
);
list_append
(
bookie
,
smtp_record
);
/* Set MH context */
current_folder
=
mu_tilde_expansion
(
current_folder
,
"/"
,
NULL
);
if
(
strchr
(
current_folder
,
'/'
)
==
NULL
)
{
char
*
p
=
mu_get_homedir
();
asprintf
(
&
current_folder
,
"mh:%s/Mail/%s"
,
p
,
current_folder
);
if
(
!
current_folder
)
{
mh_error
(
"low memory"
);
exit
(
1
);
}
}
else
if
(
strchr
(
current_folder
,
':'
)
==
NULL
)
{
char
*
p
;
p
=
xmalloc
(
strlen
(
current_folder
)
+
4
);
strcat
(
strcpy
(
p
,
"mh:"
),
current_folder
);
current_folder
=
p
;
}
ctx_name
=
xmalloc
(
strlen
(
current_folder
)
+
sizeof
(
MH_SEQUENCES_FILE
)
+
2
);
sprintf
(
ctx_name
,
"%s/%s"
,
current_folder
+
3
,
MH_SEQUENCES_FILE
);
if
(
mh_read_context_file
(
ctx_name
,
&
header
)
==
0
)
{
char
buf
[
64
];
size_t
n
;
if
(
!
header_get_value
(
header
,
"cur"
,
buf
,
sizeof
buf
,
&
n
))
current_message
=
strtoul
(
buf
,
NULL
,
10
);
header_destroy
(
&
header
,
NULL
);
}
free
(
ctx_name
);
}
int
mh_read_context_file
(
char
*
path
,
header_t
*
header
)
{
int
status
;
char
*
blurb
;
struct
stat
st
;
FILE
*
fp
;
if
(
stat
(
path
,
&
st
))
return
errno
;
blurb
=
malloc
(
st
.
st_size
);
if
(
!
blurb
)
return
ENOMEM
;
fp
=
fopen
(
path
,
"r"
);
if
(
!
fp
)
{
free
(
blurb
);
return
errno
;
}
fread
(
blurb
,
st
.
st_size
,
1
,
fp
);
fclose
(
fp
);
if
(
status
=
header_create
(
header
,
blurb
,
st
.
st_size
,
NULL
))
free
(
blurb
);
return
status
;
}
char
*
mh_read_formfile
(
char
*
name
)
{
FILE
*
fp
;
struct
stat
st
;
char
*
ptr
;
size_t
off
=
0
;
char
*
format_str
;
if
(
stat
(
name
,
&
st
))
{
mh_error
(
"can't stat format file %s: %s"
,
name
,
strerror
(
errno
));
return
;
}
fp
=
fopen
(
name
,
"r"
);
if
(
!
fp
)
{
mh_error
(
"can't open format file %s: %s"
,
name
,
strerror
(
errno
));
return
;
}
format_str
=
xmalloc
(
st
.
st_size
+
1
);
while
((
ptr
=
fgets
(
format_str
+
off
,
st
.
st_size
-
off
,
fp
))
!=
NULL
)
{
int
len
=
strlen
(
ptr
);
if
(
len
==
0
)
break
;
if
(
len
>
0
&&
ptr
[
len
-
1
]
==
'\n'
)
ptr
[
--
len
]
=
0
;
off
+=
len
;
}
format_str
[
off
]
=
0
;
fclose
(
fp
);
return
format_str
;
}
static
char
*
my_name
;
static
char
*
my_email
;
...
...
Please
register
or
sign in
to post a comment