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
bb98dcbb
...
bb98dcbbf1f31c0fec3046765c85d12d47291ec8
authored
2001-10-23 22:28:40 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
New function mu_get_user_email.
1 parent
fe26a0f9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
mailbox/mutil.c
mailbox/mutil.c
View file @
bb98dcb
...
...
@@ -29,6 +29,7 @@
#include <pwd.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <mailutils/mutil.h>
#include <mailutils/iterator.h>
...
...
@@ -404,3 +405,40 @@ getpwnam_virtual (const char *u)
}
#endif
char
*
mu_get_user_email
(
char
*
name
)
{
size_t
size
;
char
hostname
[
256
];
struct
hostent
*
hp
;
char
*
domainpart
;
char
*
email
;
if
(
!
name
)
{
struct
passwd
*
pw
=
getpwuid
(
getuid
());
if
(
!
pw
)
{
errno
=
EINVAL
;
return
NULL
;
}
name
=
pw
->
pw_name
;
}
gethostname
(
hostname
,
sizeof
hostname
);
hostname
[
sizeof
(
hostname
)
-
1
]
=
0
;
if
(
hp
=
gethostbyname
(
hostname
))
domainpart
=
hp
->
h_name
;
else
domainpart
=
hostname
;
email
=
malloc
(
strlen
(
name
)
+
strlen
(
domainpart
)
+
2
);
if
(
!
email
)
{
errno
=
ENOMEM
;
return
NULL
;
}
sprintf
(
email
,
"%s@%s"
,
name
,
domainpart
);
return
email
;
}
...
...
Please
register
or
sign in
to post a comment