Author Topic: How to get the cPanel username (not the email, but the main username) Anyone?  (Read 3448 times)

Offline cass

  • Newbie
  • *
  • Posts: 2
Hello, ;D

Im trying to make "Mark as Junk 2" works on a cpanel server, using the cmd driver to do "Spam Assassin" learning for the spam or ham,  so, when someone clicks a mail as spam, the system will "learn" and save this email for future mark it as spam again and have the account cleaner automatically.

The problem is that, the plugin, comes with a few variables you can use, but that they use the full email, or parts of the email or the domain, but in Cpanel, the Spamassasin preferences file that we need to modify, is on the "username", thay may have nothing to do with the domain or assigned email.  (like, usename could be "pepe" email could be info@juan.com,  ... so, how does I save to a variable "pepe" username in wich the info@juan.com is running?)

I use a command like this :
sa-learn --ham or --spam --prefs-file=/home/%u/.spamassassin/user_prefs %f

but, the %u, returns the full email used to login on cpanel webmail... and not the true username.

Say I have a username called "user", wich home dir is /home/user, he have a domain "mydomain.com", and there, he created an account "info@mydomain.com" wich he used with roundcube. 
So basically... using the %u or %l variables, I get or the full email, or the first part of the email, but I need the "real username" or at least, the home directory location ie:  "/home/user"

Using %u = BAD (email)
[19-Jul-2016 19:43:08 -0500]: <cbcf6nvu> /usr/local/bin/sa-learn --spam --prefs-file=/home/info@mydomain.com/.spamassassin/user_prefs /var/cpanel/roundcube/tmp/rcmSALearnW3TstE

Using %l = BAD (not username, but first part of the email)
[20-Jul-2016 05:02:14 -0500]: <gejm84ns> /usr/local/bin/sa-learn --spam --prefs-file=/home/info/.spamassassin/user_prefs /var/cpanel/roundcube/tmp/rcmSALearnqhGJ7V


The plugin, takes this %u or %l like this :
              $command = str_replace('%u', $_SESSION['username'], $command);
              $command = str_replace('%l', $rcmail->user->get_username('local'), $command);
              $command = str_replace('%d', $rcmail->user->get_username('domain'), $command);

So, what would be the $rcmail command to get the "true" username, or the "home directory"  so the final command looks like :

/usr/local/bin/sa-learn --spam --prefs-file=/home/user/.spamassassin/user_prefs /var/cpanel/roundcube/tmp/rcmSALearnW3TstE



Thanks for you help!

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,879
    • SKaero - Custom Roundcube development
The problem is that Roundcube doesn't know the cPanel username, that information isn't something thats passed to Roundcube by the mail server and Roundcube isn't running from the users directory so its not going to know what the account is. My suggestion would be to make a api query to cPanel to find what account goes with what email address.