Welcome, Guest
Please Login or Register.
Lost Password?
How to recover email in php (1 viewing)
Post Reply

TOPIC: How to recover email in php

#7223
julien.pham (User)
Posts: 62
graphgraph
How to recover email in php 2007/09/11 22:22  
Hi, I have two questions... virtualmin supports users as unix users or ldap ones. I tried to configure ldap on my server, but it seems too hard for me, so I gave up... virtualmin GPL does not support users as mysql users ?

And users as unix users, isn't there a problem when we have many users ?

Now, my second question... in php, how can I recover the email of a user? As the email is not stored in the passwd file, it has something to do with /etc/postfix/virtual.

Thanks
  The administrator has disabled public write access.
#7226
Joe (Admin)
Posts: 4124
graph
Re:How to recover email in php 2007/09/11 23:00  
And users as unix users, isn't there a problem when we have many users ?

No.

LDAP (and maybe MySQL, but I'm not a fan for user storage) is useful only if you have many machines. Other problems will come up long before you have a "too many users" problem with local UNIX users. (Specifically, by the time you get to 500 or so users, even the fastest machine will be working too hard handling spam and AV filtering.)

LDAP and MySQL users are slower than local users for almost any number of local users. The benefit is in allowing you to have users on many machines. It's never worth the additional overhead for a single machine (or even two or three machines with the same users). MySQL is pretty much always a poor choice, as well. LDAP is far better suited to user storage.

Now, my second question... in php, how can I recover the email of a user? As the email is not stored in the passwd file, it has something to do with /etc/postfix/virtual.

What's PHP got to do with it?

What are you trying to recover? Just the email address? I'm confused. ;-)
  The administrator has disabled public write access.
#7227
julien.pham (User)
Posts: 62
graphgraph
Re:How to recover email in php 2007/09/11 23:15  
Mmm yes I'll try to explain better...
I do try squirrelmail as a webmail.
But in squirrelmail, username and email address is empty, until the user fills it, and I do not like that.

And if those fields remain empty, then when someone sends a mail, the from field looks like "firstname.lastname.domain@domain.com". Without even the user realname.

There is a squirrelmail plugin which fills those fields, or at least it fills only the full name, with the posix php function posix_getpwnam. But this function works only to recover the full name, as the mail address is not stored in the /etc/passwd file.

So I would like to edit this function, so the mail address will be collected as well, but I have not a single idea on how to collect the mail address in php with the way virtualmin stores it... perhaps I have to read /etc/postfix/virtual to find the mail address? But how to do it?

Thanks
  The administrator has disabled public write access.
#7231
julien.pham (User)
Posts: 62
graphgraph
Re:How to recover email in php 2007/09/12 00:42  
Ok I found a way... in php I use functions fopen and fgetcsv to read the content of /etc/postfix/virtual :)
  The administrator has disabled public write access.
#7240
Joe (Admin)
Posts: 4124
graph
Re:How to recover email in php 2007/09/12 09:30  
Awesome.

You should post what you come up with. Others are probably also interested (we still haven't convinced folks that Usermin is a better webmail client, and I guess it does still have a few ugly usability glitches).

For most folks the standard SquirrelMail virtual users plugin works fine (which I believe is based on the hostname you connect to), but one that knows about the virtual map is probably smarter.
  The administrator has disabled public write access.
#7269
julien.pham (User)
Posts: 62
graphgraph
Re:How to recover email in php 2007/09/13 05:39  
^^ I think squirrelmail is a wonderful mail client as well, and was easier to configure the way I want... and the plugin system is cool too... and... errr... sure your webmail is cool too, but I prefer the squirrelmail look and feel ^^ it looks more like classic webmails... the way to go to read mail for example, in your webmail you have to click mail, then read mail if I remember well... and the way you change password... in login then change password... in squirrelmail there is an "option" tabs then a change password menu... easier to find for users used to other webmails ^^

So what I came up with... squirrelmail has a plugin with the name retrieveuserdata which has several features such as the possibility to retrieve user datas from ldap, mysql, pgsql, and from unix password file. This is this last one which should be used with virtualmin.

But the problem with this plugin is that it just uses POSIX posix_getpwnam function to do this, so it retrieves just the user name, as the email is not in the passwd file. So I changed this file to be able to retrieve the user email as well. How did I do that? I opened in read only the /etc/postfix/virtual file, and then I searched for the username. When I find the good usernamen, I return the email.

I attach the passwd.php file to this message for people who are interested. My email is in this file as well...

Second problem in this plugin is that each time it retrieves user datas, it adds a new identity, what I do not want. As on my mail server users are not allowed to change their identity, and I don't care about multiple identities. There is a patch on the web to fix this, but I find this patch too hard to use, so I just edited the setup.php file of this plugin.

After the lines :
Code:

         // get number of already used identities          $idents = getPref($data_dir, $username, 'identities');          if(empty($idents) || !isset($idents)) { $idents = 0; }


I added the lines :
Code:

         // This Line was added to use only ONE identity          $idents = 0;



This way squirrelmails believe there is no identity yet and will not have a new one, it will replace old one...

Have a good day with those tricks...
  The administrator has disabled public write access.
#7270
julien.pham (User)
Posts: 62
graphgraph
Re:How to recover email in php 2007/09/13 05:41  
Mmmm ok I was not allowed to post a php file, so here is the code of the passwd.php one :

Code:

<?php   /*    *  passwd.php    *    *  Passwd File Access 0.1    *  SquirrelMail Retrieve User Data Plugin    *  By Ralf Kraudelt <kraude@wiwi.uni-rostock.de>    *    *  Retrieve username from GECOS field in passwd file through POSIX function    *    *  Modified by Julien PHAM <julien.pham@mindenice.fr> to handle    *  virtual users in /etc/postfix/virtual file    *    */   function retrieve_data ($uid, $passwd) {     $error = 0;     $result = posix_getpwnam( $uid );     $common_name = strtok($result['gecos'],',');     if ( empty($common_name) ) {        $error = 1;     }     $MAIL_ADDRESS = "";     $handle = fopen("/etc/postfix/virtual", "r");     while ((($data = fgetcsv($handle, 1000, chr(9))) !== FALSE) AND ($MAIL_ADDRESS=="")) {       if ($data[1]==$uid) {         $MAIL_ADDRESS=$data[0];       }     }     fclose($handle);     return array('error'=>$error, 'common_name'=>$common_name, 'mail_address'=>$MAIL_ADDRESS);   } ?>

  The administrator has disabled public write access.
#7273
Joe (Admin)
Posts: 4124
graph
Re:How to recover email in php 2007/09/13 07:18  
^^ I think squirrelmail is a wonderful mail client as well, and was easier to configure the way I want... and the plugin system is cool too... and... errr... sure your webmail is cool too, but I prefer the squirrelmail look and feel ^^ it looks more like classic webmails... the way to go to read mail for example, in your webmail you have to click mail, then read mail if I remember well... and the way you change password... in login then change password... in squirrelmail there is an "option" tabs then a change password menu... easier to find for users used to other webmails ^^

You're using the wrong Usermin theme. Usermin with the Virtualmin Framed theme now has a sidebar menu, just like traditional webmail clients, a change password link in the menu, and it opens directly to mail (no clicking Mail:Read Mail). It also gets email addresses right automatically, when configured correctly (it knows how to find the email address from the virtual map).

As far as I know, Usermin as we ship it today is better than Squirrel on all counts (except one...the first time you login, you have to "login" twice, because you login to Usermin, and then you login to the IMAP server...this only happens once, though).
  The administrator has disabled public write access.
#7279
julien.pham (User)
Posts: 62
graphgraph
Re:How to recover email in php 2007/09/13 08:39  
Why is it better on all count? :) Does it have many plugins and easy way to create plugins as in squirrelmail?

In squirrel I have plugins to translate mails, to check spelling, to handle spams a lot of way, the possibility to check against disk quotas, and to highlight mails with colors according to filters. And there are dozens of plugins I didn't installed yet but which are quite useful...

And I was able to access my squirrelmail with an address like https://webmail.mydomain.com... And with usermin?

And where can I find this new theme?

And... if I want to try usermin again, I should find why it is broken :)
  The administrator has disabled public write access.
#7281
julien.pham (User)
Posts: 62
graphgraph
Re:How to recover email in php 2007/09/13 09:08  
Edit : not broken anymore... btw why can't I edit my posts? It says "hacking attempt"
  The administrator has disabled public write access.
Post Reply
get the latest posts directly to your desktop

Talk and Get Help

Support
Forums
Bugs and Issues

Get Virtualmin

OS Support
Buy Online
Download
Copyright 2005-2007 Virtualmin, Inc. All rights reserved.