Why is $this->mail_smtppass already set before save() in OutboundEmailAccounts module?

Hi,

I’m customizing the OutboundEmailAccounts module and noticed something strange.

In my overridden save() function, I’m checking if the password field is empty like this:

if (!$this->mail_smtppass && $this->id) {
    $bean = BeanFactory::newBean('OutboundEmailAccounts');
    $bean->retrieve($this->id);
    if (!$bean->mail_smtppass) {
        $this->mail_smtppass = null;
    } else {
        $this->mail_smtppass = $bean->mail_smtppass;
    }
}

However, even if I don’t enter any password in the Edit View, the condition doesn’t pass — because $this->mail_smtppass already has a value

do anyone know how this value is coming i am not able to find

Well… what does it contain, when not empty? That should give you a clue.

My guess is that it contains true, but please check and tell us

Its basically contains some previous password cache. encoded by blowfish.

Can you show the rest of the PHP file? I’d like to try and understand what $this is, exactly.

You don’t want a DB row, you want the fields coming from the screen; that’s probably one of the arguments going into the hook

OutboundEmailAccounts.txt.zip (5.6 KB)

That’s the entire original file, not your custom file with a few overrides.

Or are you customizing the entire file for some reason?

If you send (or paste) some other file, please also say the exact path where you have it.

At the moment, I’m not overriding the entire file I’m just inspecting the original OutboundEmailAccounts.php file to understand the behavior. I’m noticing that even before hitting the save() method, $this->mail_smtppass already contains the previous password (encrypted via Blowfish).
I’m trying to figure out where this old password value is getting injected possibly somewhere before save()

I had a look at the file but I couldn’t make out how the code flows.

Are you able to debug with and IDE? See where the object is instantiated, and where “save” is being called from?

I’ll dig deeper into where the object is first instantiated and where the fields are assigned maybe in SugarController or one of the SugarBean::populateFromPost() methods. Will update once I trace it.

1 Like