I don't want to remove email forwarding feature. I just don't want to allow forwarding to few domains i.e. block email forwarding to AOL, Comcast accounts.
Kailash
If you have a basic understanding of Perl, you can implement this at this time using Custom Event Handlers. This is different from the function hooks we talk about in that function hooks allow you to do additional things
after an action has been performed. With Custom Event Handlers, you can create a "pre" handler that intercepts the call to Email::addforward and aborts it if certain conditions are met (e.g. the fwdemail parameter contains comcast.net).
To implement a Custom Event Handler, create a new Perl Module called CustomEventHandler.pm in /usr/local/cpanel/Cpanel/ and create a subroutine called
event in the module. You will also need to add this line of code to your event subroutine to pull in all the parameters being passed to it:
Code:
my ( $apiv, [COLOR="Red"]$type[/COLOR], [COLOR="RoyalBlue"]$module[/COLOR], [COLOR="SeaGreen"]$event[/COLOR], [COLOR="DarkOrchid"]$cfgref[/COLOR], $dataref ) = @_;
As for what each of the parameters is:
type is either
pre or
post. If the
type is
pre then that means this is before the event is happening. If the
type is
post, then the event has already happened
module is the name of the module. This will be
Cpanel:: followed by the module name from the API1 or API2 function being called. For example:
Cpanel::Email
event is the name of the function being called by API1 or API2. For example:
addforward
cfgref is a hash of the variables passed to the event. For example:
$cfgref{'fwdemail'} would contain the email address to forward email to if email forwarding was the selected option.
dataref is only used in post events. This simply contains the data returned from the event.
Your event subroutine will be called every time an action is performed in the cPanel interface (both before and after). Actions are disallowed by returning false. Therefore, return true by default and only return false when you explicitly do not want something to happen. Otherwise, you may inadvertently disable all cPanel functionality.
For example, you may want to have an if block where you see if the module is
Cpanel::Email and the event is
addforward and $cfgref{'fwdemail'} contains any of the domains you do not want mail forwarded to, and inside that block of code return false. If that if block is never executed, return true.
Returning false on a pre event will prevent that event from happening. Returning false on a post event only prevents output from that event from being displayed.
We plan to write up formal documentation on this. In the meantime, you can find some documentation in /usr/local/cpanel/hooks/README and the files it references. DO NOT EDIT EventHandler.pm! Instead, create your own CustomEventHandler.pm for your own event handling functions.
I only recommend this if you are familiar with Perl as this can only be done in Perl. If you are not familiar with Perl, I recommend reading a book that can introduce you to the language so you become familiar with the syntax of Perl.