26 (edited by apmuthu 02/02/2013 05:36:52 pm)

Re: email of quotes

In includes/session.inc, outside of the class definition, in the function login_timeout() line 402 is:

$_SESSION["wa_current_user"] = new current_user();

Class current_user is defined in includes/current_user.inc, having class variables $loginname, $name and $username all set to empty strings in the constructor at line 42.

current_user::login() method on successful authorisation at line 81:

$myrow = get_user_by_login($loginname);

and sets the current_user class variables

                $this->name = $myrow["real_name"];
                $this->pos = $myrow["pos"];
                $this->loginname = $loginname;
                $this->username = $this->loginname;
                $this->prefs = new user_prefs($myrow);
                $this->user = @$myrow["id"];

If the session variable user is available, ordinarily from the above code, the session variable name should also be available.

When a login timeout occurs, this may not get executed fully and some session variables may get unset (needs to be checked).

Somewhere the session variablenameis getting set to an empty string after having been logged in, if it is empty.

Hence check by replacing the line 269 in reporting/includes/pdf_report.inc with any of the following:

$this->user = $_SESSION["wa_current_user"]->loginname;

// or

$this->user = $_SESSION["wa_current_user"]->username;

and see what happens!

27 (edited by apmuthu 02/02/2013 05:19:29 pm)

Re: email of quotes

@ed10: While I was documenting the code trace back to where the variables were set, you beat me to it!

You can actually dump the specific session variable:

echo print_r($_SESSION["wa_current_user"], true);

at the location of the send() and see what is the output!

Line 95 in admin/db/users_db.inc in function get_users_by_login():

$sql = "SELECT * FROM ".TB_PREF."users WHERE user_id=".db_escape($user_id);

Hence all fields must be available and in your instance, the real_name field may not have been set, though in the email instance, the username may be okay.

Re: email of quotes

Only 2 files use the  $_SESSION["wa_current_user"]->loginname variable:

Line 82 in includes/errors.inc:

        $user = @$_SESSION["wa_current_user"]->loginname;

and Line 55 in reporting/includes/printer_class.inc:

        $ctrl = "H".$server."\nP". substr($_SESSION["wa_current_user"]->loginname,0,31) 

It is always the same as $_SESSION["wa_current_user"]->username - would the devs want to standardize?.

Re: email of quotes

Ok, got it figured out. The last test email came in just like I wanted it to (almost-the salutation is not right yet). For the user I was logged in for didn't have any entry in user table for real_name so that is why it came up blank.  In the line:
$this->user = $_SESSION["wa_current_user"]->name;
'name' is taken from the 'real_name' field in the user table. (I thought it was the user_id)

At least that is what it looks like right now.  Time to take a break and look at it all again tomorrow to see if I have it all the way I want it.

Tomorrow is work on Mercurial day also, can't seem to get it to work right for me.

30 (edited by apmuthu 02/02/2013 06:09:54 pm)

Re: email of quotes

Final solution:
1. Fix the reply to header variable as in Post 20 of this thread.
2. Make sure the real_name field in the users table for the logged in use is populated. Otherwise take the fix from Post 25 in this thread.

Post's attachments

fa_mail.patch 1 kb, 3 downloads since 2013-02-02 

You don't have the permssions to download the attachments of this post.

Re: email of quotes

The patch didn't work here.  When I did the patch and took the  '-f sales@mydomain.com' out of var $add_params = '-f sales@mydomain';  then the returnpath went to: Return-Path: <"www-data@user"@mydomain.com>
so that is not right. with the -f flag in the add_parms it works.
I don't think you can set that Return-Path in the header, has to be separate parameter sent to postfix.

Take a look at:
me at arronwoods dot com
1 year ago
I've had all sorts of problems with scripts that don't set the "-f user@example.org" parameter when using mail() if postfix is the sendmail agent. ...
in http://php.net/manual/en/function.mail.php


Re: email of quotes

Looking at $_SESSION["wa_current_user"]  it seems that the current user's email address is not set.  Is that right?
If it isn't, I am curious why it isn't.  If it were set then I could set the add_parm for the 'reply to' using the email of the user who actually sends the email instead of a fixed address.  Would be a little bit nicer.

What would really be nice would be putting all this kind of stuff into the custom report (in this case rep111 in company directory) and not the main code pages like pdf_report.inc and class.mail.inc. That would keep the custom stiff together and the main code less hacked by various FA users.  Maybe it is not even possible, but possible or not still would be nice smile


33 (edited by apmuthu 02/03/2013 12:23:53 am)

Re: email of quotes

What happens if both the headers method and the -f method are used together for Reply-to - does the mail deliver as desired? Make sure the users table has the email of the logged in user and try $_SESSION["wa_current_user"]->email and see if it appears correctly.

The RFC2822  uses CRLF and FA's class.mail.inc uses LF only.

Article 3.6.2 in the RFC2822 states:

..... an optional reply-to field MAY also be
   included, which contains the field name "Reply-To" and a
   comma-separated list of one or more addresses.

from            =       "From:" mailbox-list CRLF

sender          =       "Sender:" mailbox CRLF

reply-to        =       "Reply-To:" address-list CRLF


Maybe some non compliant versions of Postfix may need the additional parameters like -f.....

Caveat - in some mail systems:

It turns out that a internet/dos style newline (\r\n) in the headers were converted to \r\r\n (ie: something mindlessly replaced all \n with \r\n without seeing if \n was already preceded by \r)

[size=8]Composed/Posted with WYSIWYG BBCode Editor[/size]

Re: email of quotes

I tried this:
earlier and it gave me an error -- from my memory something like no $email var defined.

When I did: echo '<pre>' . print_r($_SESSION, true) . '</pre>';
it shows no email in the wa_current_user array.       

I have not tried to use both methods.

I am using the latest verison of postfix for ubuntu from ubuntu repository so would be greatly surprised if my Postfix was non-compliant.

Re: email of quotes

Please check that the logged in user has an email entry in his record in the users table and then see if the $_SESSION["wa_current_user"]->email gets populated.

Unless we try having both Reply-to in header and using the -f parameter with no error, we cannot include the code in the base repo as it has to ensure that existing installs with no postfix and just sendmail will still work.

Re: email of quotes

In currrent_user.inc there is nothing about email so how can $_SESSION["wa_current_user"]->email get populated? I have emails for all the users.  when I print $_SESSION I get the following array with values removed:
    [wa_current_user] => current_user Object
            [role_set] => Array
                (   edited long list

            [old_db] =>
            [logged] => 1
            [ui_mode] => 1
            [prefs] => user_prefs Object
                (   edited long list

            [cur_con] => 0

No email.


Re: email of quotes

@ed10: thanks for the info.

Since the users.email field is not being used anywhere in the code if acquired using get_user_by_login() (as is done here in line 81 of includes/current_user.inc), the following patch will ensure it's availability in any script that uses it:

--- old/includes/current_user.inc    Thu Jan 17 19:16:02 2013
+++ new/includes/current_user.inc    Mon Feb 04 05:42:49 2013
@@ -22,6 +22,7 @@
     var $loginname;
     var $username;
     var $name;
+    var $email;
     var $company; // user's company
     var $pos;
     var $access;
@@ -120,6 +121,7 @@
                 $this->username = $this->loginname;
                 $this->prefs = new user_prefs($myrow);
                 $this->user = @$myrow["id"];
+                $this->email = @$myrow["email"];
                 $this->logged = true;
                 $this->last_act = time();
Post's attachments

current_user-email.patch 572 b, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Re: email of quotes

This has been fixed and sent to HG repository.

The file /includes/current_user.inc can also be doenloaded here.

Please download and replace in /includes/current_user.inc.


Post's attachments

current_user.inc 15.6 kb, 2 downloads since 2013-02-04 

You don't have the permssions to download the attachments of this post.

39 (edited by apmuthu 02/04/2013 10:39:44 am)

Re: email of quotes

Thank Joe. HG Changeset 3178 did it.

Now in order to leverage it, we need new config variables or sys_prefs entries to switch between
the default (current for backwards compatibility) Comapny Name and Company EMail and
the optional User Real name and User EMail
in determining the mail sender name and Reply-to name.
Sys_prefs would be preferable as they can be set on a per company basis. It should be coded to fall back to the other if one is absent.