def get_server_ipaddress(self, trust):
log.debug("<STR_LIT>".format(trust))<EOL>if not trust.strip():<EOL><INDENT>return<EOL><DEDENT>received = self.message.get_all("<STR_LIT>", [])<EOL>for i in received:<EOL><INDENT>i = ported_string(i)<EOL>if trust in i:<EOL><INDENT>log.debug("<STR_LIT>".format(trust, i))<EOL>check = REGXIP.findall(i[<NUM_LIT:0>:i.find("<STR_LIT>")])<EOL>if check:<EOL><INDENT>try:<EOL><INDENT>ip_str = six.text_type(check[-<NUM_LIT:1>])<EOL>log.debug("<STR_LIT>".format(<EOL>ip_str, i))<EOL>ip = ipaddress.ip_address(ip_str)<EOL><DEDENT>except ValueError:<EOL><INDENT>return<EOL><DEDENT>else:<EOL><INDENT>if not ip.is_private:<EOL><INDENT>log.debug("<STR_LIT>".format(ip_str))<EOL>return ip_str<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>
Return the ip address of sender

Overview:
Extract a reliable sender IP address heuristically for each message.
Although the message format dictates a chain of relaying IP
addresses in each message, a malicious relay can easily alter that.
Therefore we cannot simply take the first IP in
the chain. Instead, our method is as follows.
First we trust the sender IP reported by our mail server in the
Received headers, and if the previous relay IP address is on our trust
list (e.g. other well-known mail services), we continue to
follow the previous Received line, till we reach the first unrecognized
IP address in the email header.

From article Characterizing Botnets from Email Spam Records:
    Li Zhuang, J. D. Tygar

In our case we trust only our mail server with the trust string.

Args:
    trust (string): String that identify our mail server

Returns:
    string with the ip address