ptonev.com
November 20, 2017, 07:10:51 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: subject of email  (Read 20118 times)
Patches
Guest
« on: September 24, 2004, 07:40:08 pm »

Is there anyway to retrive the subject of each emails, and forward those on.

I dont want the email itself,  just the subject line.   I really dont even need the sender's info,  just the subject would be great.  :-)
Logged
ptonev
Administrator
Newbie
*****
Posts: 135


3119712
View Profile WWW
« Reply #1 on: September 24, 2004, 09:43:55 pm »

Hi,

> Is there anyway to retrive the subject of each emails, and forward those on.

Yes have way, but must make change on script.

That version you use: socket or IMAP-i?

best regards
Logged
Anonymous
Guest
« Reply #2 on: September 25, 2004, 04:47:39 am »

Do I have to use the imap system,  or does just stealing the explode routine from the imap system work on the pop3??
Logged
Patches
Guest
« Reply #3 on: September 25, 2004, 05:02:01 am »

Im using the pop3 verision  the standard one I guess,  not the imap one....

Here is what Im looking for in my message I send to my cell phone.

From: (will be my mailserver)
Subject: 3 New Emails
Text:
Subject: New Design looks good
Subject: Please send photos
Subject: Payment Sent




I do not care to see who they are from,  just the subject lines only.  I can usually tell from that who they are from.
Logged
ptonev
Administrator
Newbie
*****
Posts: 135


3119712
View Profile WWW
« Reply #4 on: September 25, 2004, 10:11:37 am »

Hi, Patches.

Try this:

Code:
find in line 88:
$pos = strpos($v, "From:");

replace with :
$pos = strpos($v, "Subject:");


find in line 96:
return trim(substr($v, 5));

replace with :
return trim(substr($v, 8));


find in line 138:
$from = __mnotify_get_simple_email($from);

replace with :
// $from = __mnotify_get_simple_email($from);


I think that will be enough to solved you question.
Logged
Anonymous
Guest
« Reply #5 on: September 27, 2004, 05:41:07 pm »

That worked,

but if there is only one email, I dont get the subject.   Appears to be a loop problem...
Logged
ptonev
Administrator
Newbie
*****
Posts: 135


3119712
View Profile WWW
« Reply #6 on: September 28, 2004, 02:54:15 am »

This is a very strange...

Can you post example or describe situation...
Logged
Patches
Guest
« Reply #7 on: September 28, 2004, 09:17:07 am »

Here is my Config File (edit of course)

Code:

#host;user;password;mailto;subject text;body text
nwdinc.net;email address;pass;XXXXXXXXXXX@messaging.sprintpcs.com;%new% - %emails%;


If I only have one email come into my email box, I get this on my phone:

From: nwdinc@comet.fast-servers.net   <--  This my server,  understand that

Message: Subject: 1 - .

And then its time stamped.


But if there is two messages then I get:

From: nwdinc@comet.fast-servers.net
Message: Subject:  2 - Subject from Message 1,  Subject from Message 2

Here is the file Im using.

Code:

<?php

define
&#40;"MNOTIFY_CFG_PATH", "./"&#41;;
define&#40;"MNOTIFY_CFG_NAME", "phpMailNotification.cfg"&#41;;
define&#40;"MNOTIFY_SUBJECT", "%new% new from %total% total email&#40;s&#41; in %account%."&#41;;
define&#40;"MNOTIFY_MESSAGE", "%emails%"&#41;;

//
// __mnotify_read_file - read content from file
//
function __mnotify_read_file&#40;$name&#41;
&#123;
$contents false;

if&#40;file_exists&#40;$name&#41;&#41;
&#123;
if&#40;$fd = @fopen&#40;$name, "r"&#41;&#41;
&#123;
$contents fread&#40;$fd, filesize&#40;$name&#41;&#41;;

fclose&#40;$fd&#41;;
&#125;
&#125;

return $contents;
&
#125;

//
// __mnotify_write_file - write data to file
//
function __mnotify_write_file&#40;$name, $data&#41;
&#123;
if&#40;$fd = @fopen&#40;$name, "w"&#41;&#41;
&#123;
fwrite&#40;$fd, $data&#41;;
fclose&#40;$fd&#41;;

return true;
&#125;
else
&#123;
return false;
&#125;
&#125;

function __mnotify_get_simple_email&#40;$str&#41;
&#123;
$open strpos&#40;$str, "<"&#41;;
$close strpos&#40;$str, ">"&#41;;

if&#40;&#40;$open === false&#41; && &#40;$close === false&#41;&#41;
&#123;
return $str;
&#125;

return substr&#40;$str, $open + 1, $close - $open - 1&#41;;
&#125;

function __mnotify_get_from_mail&#40;$fp, $number, $size&#41;
&#123;
fputs&#40;$fp, "RETR $number\n"&#41;;
$line fgets&#40;$fp, 200&#41;;

$line fread&#40;$fp, $size&#41;;
$line explode&#40;"|", str_replace&#40;"\n", "|", $line&#41;&#41;;

if&#40;is_array&#40;$line&#41; && &#40;count&#40;$line&#41; > 0&#41;&#41;
&#123;
foreach&#40;$line as $v&#41;
&#123;
$pos strpos&#40;$v, "Subject&#58;"&#41;;

if&#40;$pos === false&#41;
&#123;
// noop
&#125;
else
&#123;
return trim&#40;substr&#40;$v, 8&#41;&#41;;
&#125;
&#125;
&#125;

return false;
&
#125;

function __mnotify_read_mails&#40;$fp, $list, $msgs&#41;
&#123;
$count $list[0&#93;;
unset&#40;$list[0&#93;&#41;;

$get true;

if&#40;$count > $msgs&#41;
&#123;
for&#40;$i = 1; $i <= $msgs; $i++&#41;
&#123;
unset&#40;$list[$i&#93;&#41;;
&#125;
&#125;
else if&#40;$count < $msgs&#41;
&#123;
&#125;
else
&#123;
$get false;
&#125;

if&#40;is_array&#40;$list&#41; && &#40;count&#40;$list&#41; > 0&#41; && $get&#41;
&#123;
$mlist "";

foreach&#40;$list as $v&#41;
&#123;
$vv explode&#40;" ", $v&#41;;

if&#40;is_array&#40;$vv&#41; && &#40;count&#40;$vv&#41; == 2&#41;&#41;
&#123;
$sep = &#40;strlen&#40;$mlist&#41; > 0&#41;? ", "&#58; "";
$from __mnotify_get_from_mail&#40;$fp, $vv[0&#93;, $vv[1&#93;&#41;;
// $from = __mnotify_get_simple_email&#40;$from&#41;;

$mlist $mlist.$sep.$from;
&#125;
&#125;

return $mlist;
&#125;
else
&#123;
return "";
&#125;
&#125;

//
// __mnotify_check_mail - check email account
//
function __mnotify_check_mail&#40;$host, $port, $user, $pass, $msgs&#41;
&#123;
$count 0;

$fp fsockopen&#40;$host, $port, $errno, $errstr&#41;;

if&#40;!$fp&#41;
&#123;
// could not open socket connection
return false;
&#125;
else
&#123;
$r fgets&#40;$fp, 200&#41;;

if&#40;substr&#40;$r, 0, 3&#41; == "+OK"&#41;
&#123;
fputs&#40;$fp, "USER $user\n"&#41;;
fgets&#40;$fp, 200&#41;;

   fputs&#40;$fp, "PASS $pass\n"&#41;;
$r fgets&#40;$fp, 200&#41;;

if&#40;substr&#40;$r, 0, 3&#41; == "+OK"&#41;
&#123;
   fputs&#40;$fp, "STAT\n"&#41;;
$r fgets&#40;$fp, 200&#41;;

if&#40;substr&#40;$r, 0, 3&#41; == "+OK"&#41;
&#123;
$r explode&#40;" ", $r&#41;;
$count $r[1&#93;;

   fputs&#40;$fp, "LIST\n"&#41;;
$list fgets&#40;$fp, 200&#41;;

$mlist "";

if&#40;substr&#40;$list, 0, 3&#41; == "+OK"&#41;
&#123;
$list = array&#40;&#41;;
$list[0&#93; = $count;

for&#40;$i = 0; $i < $count; $i++&#41;
&#123;
$list[&#93; = fgets&#40;$fp, 200&#41;;
&#125;

$mlist __mnotify_read_mails&#40;$fp, $list, $msgs&#41;;
&#125;

fputs&#40;$fp, "QUIT\n"&#41;;
   fclose&#40;$fp&#41;;

   if&#40;$mlist != ""&#41;
   &#123;
return array&#40;$count, $mlist&#41;;
   &#125;
   else
   &#123;
return $count;
   &#125;
&#125;
else
&#123;
// server said&#58; $r
return false;
&#125;
&#125;
else
&#123;
// server said&#58; $r
return false;
&#125;
&#125;
else
&#123;
// bad connection string
return false;
&#125;
&#125;
&#125;

// read cfg file
$contents __mnotify_read_file&#40;MNOTIFY_CFG_PATH.MNOTIFY_CFG_NAME&#41;;

if&#40;$contents === false&#41;
&#123;
echo "Can't read config file.<b>\n";
&
#125;
else
&
#123;
// parse and explode account
$accounts explode&#40;"\n", $contents&#41;;

if &#40;count&#40;$accounts&#41; > 0&#41;
&#123;
foreach&#40;$accounts as $v&#41;
&#123;
// skip comment accounts
if&#40;substr&#40;$v, 0, 1&#41; == "#"&#41;
&#123;
continue;
&#125;

// parse account on tokens
$tokens explode&#40;";", $v&#41;;

// prepare account name
$account $tokens[1&#93;;

if&#40;strpos&#40;$account, "@"&#41; === false&#41;
&#123;
$account $tokens[1&#93;."@".$tokens[0&#93;;
&#125;

// prepare account password
$password $tokens[2&#93;;

if&#40;substr&#40;$password, 0, 1&#41; == "#"&#41;
&#123;
$password base64_decode&#40;substr&#40;$password, 1&#41;&#41;;
&#125;

// compose account file name
$file_name $tokens[1&#93;."@".$tokens[0&#93;.".cfg";

// get subject template text
if&#40;!isset&#40;$tokens[4&#93;&#41;&#41;
&#123;
$tokens[4&#93; = MNOTIFY_SUBJECT;
&#125;

// get body template text
if&#40;!isset&#40;$tokens[5&#93;&#41;&#41;
&#123;
$tokens[5&#93; = MNOTIFY_MESSAGE;
&#125;

// read old email count
$msg_old __mnotify_read_file&#40;MNOTIFY_CFG_PATH.$file_name&#41;;

// check email
$new __mnotify_check_mail&#40;$tokens[0&#93;, 110, $tokens[1&#93;, $password, $msg_old&#41;;

if&#40;$new === false&#41;
&#123;
echo "Can't check $account account.<b>\n";
&#125;
else
&#123;
if&#40;is_array&#40;$new&#41; && &#40;count&#40;$new&#41; == 2&#41;&#41;
&#123;
$msg_new $new[0&#93;;
$body $new[1&#93;;
&#125;
else
&#123;
$msg_new $new;
$body ".";
&#125;

if&#40;$msg_new > $msg_old&#41;
&#123;
$msg_dif $msg_new $msg_old;

$_msg $tokens[4&#93;;
$_msg str_replace&#40;"%new%", $msg_dif, $_msg&#41;;
$_msg str_replace&#40;"%total%", $msg_new, $_msg&#41;;
$_msg str_replace&#40;"%account%", $account, $_msg&#41;;
$_msg str_replace&#40;"%emails%", $body, $_msg&#41;;

$_body $tokens[5&#93;;
$_body str_replace&#40;"%new%", $msg_dif, $_body&#41;;
$_body str_replace&#40;"%total%", $msg_new, $_body&#41;;
$_body str_replace&#40;"%account%", $account, $_body&#41;;
$_body str_replace&#40;"%emails%", $body, $_body&#41;;

if&#40;mail&#40;$tokens[3&#93;, $_msg, $_body, "From&#58; $account"&#41;&#41;
&#123;
echo "[$_msg&#93;, [$_body&#93;<b>\n";
&#125;
else
&#123;
echo "Can't send email to ".$tokens[3&#93;." successfully.<b>\n";
&#125;
&#125;
__mnotify_write_file&#40;MNOTIFY_CFG_PATH.$file_name, $msg_new&#41;;
&#125;
&#125;
&#125;
else
&#123;
echo "Can't extract account from config file.<b>\n";
&#125;
&#125;

?>
Logged
ptonev
Administrator
Newbie
*****
Posts: 135


3119712
View Profile WWW
« Reply #8 on: September 30, 2004, 06:43:14 pm »

Hi,

this is a very strange.

Now I tested it and all work fine. I received fine subject when I have one email.

You are sure that you not have a email with empty subject.

Best regards,
Logged
Patches
Guest
« Reply #9 on: September 30, 2004, 09:25:34 pm »

Im sure the emails dont have blank subject lines,  cause when I actually get to a computer, they are there.

After some testing, its not just a single email, where it doesnt send the subject,  it skips the first subject, no matter how many emails I have.

1 email - No subject displayed

3 emails - 2 Subjects displayed,  skipping the first one..

etc
Logged
ptonev
Administrator
Newbie
*****
Posts: 135


3119712
View Profile WWW
« Reply #10 on: October 02, 2004, 07:30:10 pm »

Hi,

really script have sometime problem with received on subjects.

You can try and IMAP-i version. It work really better.

Try it and if it work I will be say what you must fix that you read subject not email.
Logged
Patches
Guest
« Reply #11 on: October 06, 2004, 08:03:05 pm »

Ok, I switched to the IMAP one,  any tips on making it show the subject instead of sender?
Logged
ptonev
Administrator
Newbie
*****
Posts: 135


3119712
View Profile WWW
« Reply #12 on: October 06, 2004, 10:58:07 pm »

Hi,

Open phpIMAPMailNotification.php file:

Code:
find in line 102:
$header = imap_headerinfo($mbox, $i, 80, 80);
$froms = $header->from;

replace with:
$header = imap_headerinfo($mbox, $i, 1024, 1024);
$fetchsubject = $header->fetchsubject;

find in line 105:
foreach($froms AS $from)
{
$sep = (strlen($email_list) > 0)? ", ": "";
$email_list = $email_list.$sep.$from->mailbox."@".$from->host;
}

replace with:
$sep = (strlen($email_list) > 0)? ", ": "";
$email_list = $email_list.$sep.$fetchsubject;


that is, try it.
Logged
Anonymous
Guest
« Reply #13 on: October 07, 2004, 09:32:36 am »

Ok,  changed those things,  now all I get is the count,  no matter how many emails.  I never receive the subject.  :-(    If I make the changes back,  I get the sender's email addy no problem
Logged
Patches
Guest
« Reply #14 on: October 07, 2004, 09:37:52 am »

Opps forgot to say Im the one above...
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!