Anti-Telus filter

  1. #!/usr/bin/perl
  2.  
  3. $user = 'REDIR@EXAMPLE.ADDRESS';
  4. $pass = 'PASSWORD';
  5. $host = 'POP3.SERVER.ADDRESS';
  6.  
  7. %redir = (
  8.     'sender@example.address' => 'reciever@example.address'
  9. );
  10.  
  11. $sendmail = '/usr/sbin/sendmail -t';
  12. #DEBUG $sendmail = 'cat >>test2.txt';
  13.  
  14. use Mail::POP3Client;
  15.  
  16. # connection
  17. $pop = new Mail::POP3Client(HOST => $host);
  18. $pop->User($user);
  19. $pop->Pass($pass);
  20.  
  21. $pop->Connect() >= 0 || die $pop->Message();
  22.  
  23. # loop through messages
  24. for ($i = 1; $i <= $pop->Count(); $i++) {
  25.     %head = ();
  26.  
  27.     foreach ($pop->Head($i)) {
  28.         /^(From|Subject|Content-type):\s+(.+)/i;
  29.         $head{lc($1)} = $2;
  30.     }
  31. #    print "From: $head{'from'}\n";
  32. #    print "Subject: $head{'subject'}\n";
  33. #    print "Content-type: $head{'content-type'}\n";
  34.  
  35.     $head{'from'} =~ /<(.+)>$/;
  36.     $email = $1;
  37.  
  38.     $body = $pop->Body($i);
  39.     $body =~ s/Email on the go, sent by TELUS//mi;
  40.  
  41.     open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!\n";
  42.     print SENDMAIL "From: $head{'from'}\nReply-to: $head{'from'}\n";
  43.     print SENDMAIL "Subject: $head{'subject'}\n";
  44.     print SENDMAIL "To: $redir{$email}\n";
  45.     print SENDMAIL "Content-type: $head{'content-type'}\n\n";
  46.     print SENDMAIL $body;
  47.     close(SENDMAIL);
  48.  
  49. #    print $body
  50. #    print "\n\n=====\n\n";
  51.  
  52.     $pop->Delete($i);
  53. }
  54.  
  55. $pop->Close;

A Perl script which removes the tag added by Telus in mobile e-mail, so that various services can work properly when using mobile e-mail from a Telus phone.

Settings

$user
The user name for the POP3 server hosting the mailbox used by the filter program.
$pass
The password for the mailbox.
$host
The name of the POP3 server.
%redir
A list of e-mail addresses. The key is the address from which a message is sent to be filtered. The value is the e-mail address to which the filtered message is sent.

This script is easily customizable for other service providers which add a static tag to e-mails that you want filtered. Simply change the regular expression on line 39, replacing the Telus tag between the first two slashes with the tag added by your service provider.