Commit bb98dcbb bb98dcbbf1f31c0fec3046765c85d12d47291ec8 by Sergey Poznyakoff

New function mu_get_user_email.

1 parent fe26a0f9
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
29 #include <pwd.h> 29 #include <pwd.h>
30 #include <unistd.h> 30 #include <unistd.h>
31 #include <string.h> 31 #include <string.h>
32 #include <netdb.h>
32 33
33 #include <mailutils/mutil.h> 34 #include <mailutils/mutil.h>
34 #include <mailutils/iterator.h> 35 #include <mailutils/iterator.h>
...@@ -404,3 +405,40 @@ getpwnam_virtual (const char *u) ...@@ -404,3 +405,40 @@ getpwnam_virtual (const char *u)
404 } 405 }
405 406
406 #endif 407 #endif
408
409 char *
410 mu_get_user_email (char *name)
411 {
412 size_t size;
413 char hostname[256];
414 struct hostent *hp;
415 char *domainpart;
416 char *email;
417
418 if (!name)
419 {
420 struct passwd *pw = getpwuid (getuid ());
421 if (!pw)
422 {
423 errno = EINVAL;
424 return NULL;
425 }
426 name = pw->pw_name;
427 }
428
429 gethostname (hostname, sizeof hostname);
430 hostname[sizeof (hostname)-1] = 0;
431
432 if (hp = gethostbyname (hostname))
433 domainpart = hp->h_name;
434 else
435 domainpart = hostname;
436 email = malloc (strlen (name) + strlen (domainpart) + 2);
437 if (!email)
438 {
439 errno = ENOMEM;
440 return NULL;
441 }
442 sprintf (email, "%s@%s", name, domainpart);
443 return email;
444 }
......