[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cobalt-developers] Keep local e-mail copy



Hello Perl cracks

I had several customers who asked me how to have their mail forwarded and still be able to read their messages in their web mailer. So, each time, me root go in /etc/mail/aliases, me find line with alias address, me add ',username' and run 'newaliases' and 'meta-verify -ua' ... So I investigated in the possibility to change the 'Email Settings' page in the GUI that would do this upon users request.

It would be convenient to have a checkbox in the GUI that would let the system keep a local copy of the forwarded e-mail message. With [_] as a checkbox, the form would look more or less like this :

+--------------------------------------------------------+
|            Email Settings - UserName                   |
|-+-+--------------------+-------------------------------|
|?| | Forward Email To   | [ forward@xxxxxxxxxxx       ] |
| | |                    |  _                            |
| | | Keep Local Copy    | [_]                           |
|-+-+--------------------+-------------------------------|
|?| |                    | [                           ] |


Checking the [_] box (I suggest to keep it off per default) would add the user name after a comma to the mail alias list in /etc/mail/aliases.

Remember the "POP Before SMTP Relaying" checkbox that Cobalt added through a package one or two years ago (now it's included in the OS)? If Cobalt would have idle resources (!), it would be a cute enhancement, wouldn't it? Or maybe I can motivate someone to help me on this?

Thank you and best regards

Meaulnes Legler
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ http://www.WaveWeb.ch ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~  Zürich, Switzerland  ~
~  tel: +41 1 260-1660  ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~


------------------------------------------------------------------------

I tried to look at the changes that have to be done, but I'm not so sure if I didn't miss something (besides the fact that the scripting surpasses my Perl knowledge...). I guess the files that need to be changed are:

 - the siteadmin script /usr/admserv/cgi-bin/.cobalt/siteUserMail/siteUserMail.cgi
 - the user script /usr/admserv/cgi-bin/.cobalt/siteUserMail/email.cgi
 - the siteadmin HTML template /usr/admserv/templates/siteUserEmail.tmpl
 - the user HTML template /usr/admserv/templates/email.tmpl
 - the language file /etc/cobalt/messages/ui.po or /etc/cobalt/messages/en_US/ui.po (yes, well, which one?)

and some "interactive variables" to be created.

This is how far I came.

Similar to the following "interactive variables" (in the language file, the templates and in the scripts):
	msgid "forwardTo"
	msgstr "Forward Email To"
	[str.forwardTo]
	NAME="forwardaddr"
	[FORWARDADDR]
the equivalents would be created (suggestions):
	msgid "forwardKeepCopy"
	msgstr "Keep Local Copy"
	[str.forwardKeepCopy]
	NAME="forwardcopy"
	[FORWARDCOPY]

In the HTML templates siteUserEmail.tmpl an email.tml in /usr/admserv/templates/, an additional line in each table cell with the text and the checkbox (after a <BR>)

	<TR>
		<TD WIDTH="26">
			<P ALIGN="CENTER"><A HREF="javascript: top.showInfo( forwardHelp );" onMouseOver="status='[str.help]'; top.showInfo( forwardHelp ); return true;"><IMG SRC="/.cobalt/images/smallest_help_but" ALIGN="BOTTOM" BORDER="0"></A>
		</TD>
		<TD><FONT COLOR=#FFFFFF>&nbsp;</FONT></TD>
		<TD WIDTH="189"><FONT COLOR=#FFFFFF>&nbsp;</FONT>[str.forwardTo]<BR>&nbsp;[str.forwardKeepCopy]</TD>
		<TD WIDTH="385"><INPUT TYPE="TEXT" NAME="forwardaddr" SIZE="32" VALUE="[FORWARDADDR]"><BR><INPUT TYPE="CHECKBOX" NAME="forwardCopy" VALUE="off" [FORWARDCOPY]></TD>
	</TR>


For the scripts in /usr/admserv/cgi-bin/.cobalt/, I must pass :-(. I just guess the changes to add the ",$username" in the alias list must be done in the two following subroutines (extract from siteUserMail/siteUserMail.cgi):

- in the event handler for the e-mail page subroutine

	sub handleSiteUserEmailPage {
		...

	    if ($err) {
		$info.=MSG_get_ui("emailAliasNotValid");
		$info.=join(', ', @badalii);
	    }
	    if( $forwardAddr && !netutil_test_emailaddr( $forwardAddr ) ) {
		$info.=eval("\"".Locale::gettext::dgettext("ui", "forwardAddrNotValid")."\"");
		$err=1;
	    }
	    if (! $err) {
		# everything is fine

		# set forward to
		if( $forwardAddr ) {
		    # build list
	            # $forwardAddr could actually be a comma separated list of aliases
	            $ret = alias_set( $userName, $forwardAddr );
		    $userObj->put('forward', $forwardAddr);
		} else {
		    # delete list
		    $ret='2';
	            if( alias_exist( $userName ) ) { $ret=alias_delete( $userName ); }
		    $userObj->put('forward', '');
		}
	        if( $ret!~/^2/o ) {
	            $info.=substr( $ret, 4 ).'<BR>';
	            $err=1;
	        }

		# set mail aliases
		my $a = join(' ', @resultAliases);
		$userObj->put("aliases" => $a);

		foreach $_ (@resultAliases) {
		    push @alii, (/\@/) ? "$_" : "$_\@$fqdn";
		}
		# add an alias to self
		push @alii, "$userName\@$fqdn";

		$ret=mail_virtuser_set_byuser( $userName, @alii );
		if( $ret!~/^2/o ) {
		    $info.=substr( $ret, 4 ).'<BR>';
		    $err=1;
		}

		...
	}

- and in the page generation subroutine

	sub genSiteUserEmailPage {
	    my ( $info )=@_;

	    my $siteObj = Cobalt::Meta->create("type" => "vsite");
	    $siteObj->retrieve($group);
	    my $fqdn = $siteObj->get("fqdn");

	    my $userName = $q->param('name');
	    my $userObj = Cobalt::Meta->create("type" => "users");
	    $userObj->retrieve($userName);
	    my $fullName = $userObj->get("fullname");

	    my ($forwardMode, $forwardAddr, @forwardList);
	    @forwardList = Cobalt::List::alias_get_vacationless( $userName );
	    if ($forwardList[0] =~ /^[134]\S*\s/) {
		# substr( $forwardList[0], 5 ).'<BR>';
		@forwardList = ();
	    }
	    if (@forwardList) {
		$forwardMode = 'CHECKED';
		$forwardAddr=join ',', @forwardList;
	    } else {
		$forwardMode = '';
	    }

	    my $aliases = $userObj->get("aliases");
	    $aliases =~ s/\s+/\n/g;
	    my $vacationMode=($userObj->get("vacation") eq 'on' ) ?'CHECKED':'';
	    my $vacationMsg=Cobalt::Vacation::vacation_get_message($userName);

	    print "content-type: text/html\nCache-Control: no-cache\n\n";

	    # Read in the template
	    open( TEMPLATE, "$Template_dir/siteUserEmail.tmpl" )
	        || die "Cannot read $Template_dir/siteUserEmail.tmpl: $!\n";

	    while( <TEMPLATE> ) {
		s/\[ALIASES\]/$aliases/o;
		s/\[FORWARDADDR\]/$forwardAddr/o;
		s/\[FULLNAME\]/$fullName/o;
		s/\[GROUP\]/$group/o;
		s/\[SITEUSEREMAILSCRIPTURL\]/$siteUserEmailScriptURL/o;
		s/\[SITEUSERLISTSCRIPTURL\]/$siteUserListScriptURL/o;
		s/\[USER_INFO\]/$info/o;
		s/\[USERNAME\]/$userName/o;
		s/\[VACATIONMODE\]/$vacationMode/o;
		s/\[VACATIONMESSAGE\]/$vacationMsg/o;

		s/\[str.([^\]]+)\]/Locale::gettext::dgettext("ui", "$1")/geo;

		print;
	    }
	    close TEMPLATE;
	}

I guess the change in email.cgi won't be very different.

------------------------------------------------------------------------

As I said, I would spend just too much time hacking around and eventually mess up something else... So any help would be very appreciated.

Thank you and best regards.