Fri 27 Jun 2003 08:10:08 AM UTC, comment #4:
My job is really dirty: i used an other email class and I have forced the code to use it. You can send mail with joined files and that's all. (no forward or Cc, etc...)
I have change in /email/inc/class.mail_send.inc.php the function smail_2822().
// ===== [ main function: smail_2822() ] =======
function smail_2822($mail_out)
{
/*print "<pre>";
print_r($mail_out);
print "</pre><hr>";*/
require_once PHPGW_SERVER_ROOT."/phpgwapi/inc/email_message.php";
$email_message=new email_message_class;
$from_name=getenv("USERNAME");
$from_address= $mail_out[from][0][plain];
$reply_name=$from_name;
$reply_address=$from_address;
$reply_address=$from_address;
$error_delivery_name=$from_name;
$error_delivery_address=$from_address;
$subject = $mail_out[subject];
if(!$subject){
$subject ="none";
}
$body = $email_message->WrapText($mail_out[body_string]);
$email_message->SetEncodedEmailHeader("From",$from_address,$from_name);
$email_message->SetEncodedEmailHeader("Reply-To",$reply_address,$reply_name);
/*
* Set the Return-Path header to define the envelope sender address to which bounced messages are delivered.
* If you are using Windows, you need to use the smtp_message_class to set the return-path address.
*/
if(defined("PHP_OS")
&& strcmp(substr(PHP_OS,0,3),"WIN"))
$email_message->SetHeader("Return-Path",$error_delivery_address);
$email_message->SetEncodedEmailHeader("Errors-To",$error_delivery_address,$error_delivery_name);
$email_message->SetEncodedHeader("Subject",$subject);
/* If you are not going to personalize the message body for each recipient,
* set the cache_body flag to 1 to reduce the time that the class will take
* to regenerate the message to send to each recipient */
$email_message->cache_body=1;
$email_message->AddQuotedPrintableTextPart($email_message->WrapText($body));
// pieces jointes
if ($mail_out['is_multipart'] == True){
foreach($mail_out[attachment_file] as $ind => $tabFile){
$email_message->AddFilePart($tabFile);
}
}
/* Iterate personalization for each recipient. */
$tab=array('to','cc','bcc');
foreach($tab as $ind => $arrayName){
$tabAddress = $mail_out[$arrayName];
if(is_array($tabAddress) && count($tabAddress) >= 1){
/*print "<pre>";
print_r($tabAddress);
print "</pre>";*/
for($recipient=0;$recipient<count($tabAddress);$recipient++)
{
/* Personalize the recipient address. */
$to_address=$tabAddress[$recipient]["plain"];
$to_name=$tabAddress[$recipient]["personal"];
//print "to_address=$to_address<br>";
$email_message->SetEncodedEmailHeader("To",$to_address,$to_name);
/* Do we really need to personalize the message body?
* If not, let the class reuse the message body defined for the first recipient above.
*/
/* print "<pre>";
print_r($email_message);
print "</pre>";*/
/* Send the message checking for eventually acumulated errors */
$error=$email_message->Send();
if(strlen($error))
break;
}
}
}
if(strlen($error)) {
echo "Error: $error\n";
}
else{
return true;
}
/* // don't start retaining the email copy until after the MTA handshake
$this->retain_copy_ignore = True;
// error code and message of failed connection
$errcode = '';
$errmsg = '';
// timeout in secs
$timeout = 5;
if ($this->debug_fake_send)
{
// arbitrary number, no significance
// we do not actually communicate with the SMTP server for a fake send
$socket = 41;
// announce the fact this is echo'd debug output, not an actual session
echo '<html><body><h2>FAKE SEND DEBUG:</h2> <h3>this is what the client would send to the SMTP server were this an actual send</h3>';
}
else
{
$smtp_server = $GLOBALS['phpgw_info']['server']['smtp_server'];
$smtp_port = $GLOBALS['phpgw_info']['server']['smtp_port'];
// some people do not set this up correctly in the site-wide admin for email
if (empty($smtp_port))
{
$smtp_port = $this->default_smtp_port;
}
// OPEN SOCKET - now we try to open the socket and check, if any smtp server responds
$socket = fsockopen($smtp_server,$smtp_port,$errcode,$errmsg,$timeout);
$this->err['server_chat'] .= htmlspecialchars('c->s: fsockopen('.$smtp_server.','.$smtp_port.','.$errcode.','.$errmsg.','.$timeout.') ; returned: '.$socket )."\r\n";
}
if (!$socket)
{
$this->err['code'] = '420';
$this->err['msg'] = $errcode.':'.$errmsg;
$this->err['desc'] = 'Connection to '.$GLOBALS['phpgw_info']['server']['smtp_server'].':'.$GLOBALS['phpgw_info']['server']['smtp_port'].' failed - could not open socket.';
return false;
}
else
{
$rrc = $this->socket2msg($socket);
}
$mymachine = $mail_out['mta_elho_mymachine'];
$fromuser = $mail_out['mta_from'];
// START SMTP SESSION - now we can send our message. 1st we identify ourselves and the sender
$cmds = array (
"\$src = \$this->msg2socket(\$socket,\"EHLO \$mymachine\r\n\");",
"\$rrc = \$this->socket2msg(\$socket);",
"\$src = \$this->msg2socket(\$socket,\"MAIL FROM:\$fromuser\r\n\");",
"\$rrc = \$this->socket2msg(\$socket);"
);
if ($this->debug_fake_send)
{
echo '<pre>';
}
for ($src=true,$rrc=true,$i=0; $i<count($cmds);$i++)
{
eval ($cmds[$i]);
if (!$src || !$rrc)
{
return false;
}
}
// RCPT TO - now we've got to feed the to's and cc's
for ($i=0; $i<count($mail_out['mta_to']); $i++)
{
$src = $this->msg2socket($socket,'RCPT TO:'.$mail_out['mta_to'][$i]."\r\n");
$rrc = $this->socket2msg($socket);
// for lateron validation
$this->to_res[$i][addr] = $mail_out['mta_to'][$i];
$this->to_res[$i][code] = $this->err['code'];
$this->to_res[$i][msg] = $this->err['msg'];
$this->to_res[$i][desc] = $this->err['desc'];
}
if (!$this->debug_fake_send)
{
//now we have to make sure that at least one $to-address was accepted
$stop = 1;
for ($i=0;$i<count($this->to_res);$i++)
{
$rc = substr($this->to_res[$i][code],0,1);
if ($rc == 2)
{
// at least to this address we can deliver
$stop = 0;
}
}
if ($stop)
{
// no address found we can deliver to
return false;
}
}
// HEADERS - now we can go to deliver the headers!
if (!$this->msg2socket($socket,"DATA\r\n"))
{
return false;
}
if (!$this->socket2msg($socket))
{
return false;
}
// READY TO SEND MAIL: start retaining the email copy (if necessary)
$this->retain_copy_ignore = False;
// BEGIN THE DATA SEND
for ($i=0; $i<count($mail_out['main_headers']); $i++)
{
if (!$this->msg2socket($socket,$mail_out['main_headers'][$i]."\r\n"))
{
return false;
}
}
// HEADERS TERMINATION - this CRLF terminates the header, signals the body will follow next (ONE CRLF ONLY)
if (!$this->msg2socket($socket,"\r\n"))
{
return false;
}
// BODY - now we can go to deliver the body!
for ($part_num=0; $part_num<count($mail_out['body']); $part_num++)
{
// mime headers for this mime part (if any)
if (($mail_out['is_multipart'] == True)
|| ($mail_out['is_forward'] == True))
{
for ($i=0; $i<count($mail_out['body'][$part_num]['mime_headers']); $i++)
{
$this_line = rtrim($this_line = $mail_out['body'][$part_num]['mime_headers'][$i])."\r\n";
if (!$this->msg2socket($socket,$this_line))
{
return false;
}
}
// a space needs to seperate the mime part headers from the mime part content
if (!$this->msg2socket($socket,"\r\n"))
{
return false;
}
}
// the part itself
for ($i=0; $i<count($mail_out['body'][$part_num]['mime_body']); $i++)
{
$this_line = rtrim($mail_out['body'][$part_num]['mime_body'][$i])."\r\n";
// TRANSPARENCY - rfc2821 sect 4.5.2 - any line beginning with a dot, add another dot
if ((strlen($this_line) > 0)
&& ($this_line[0] == '.'))
{
// rfc2821 add another dot to the begining of this line
$this_line = '.' .$this_line;
}
if (!$this->msg2socket($socket,$this_line))
{
return false;
}
}
// this space will seperate this part from any following parts that may be coming
if (!$this->msg2socket($socket,"\r\n"))
{
return false;
}
}
// FINAL BOUNDARY - at the end of a multipart email, we need to add the "final" boundary
if (($mail_out['is_multipart'] == True)
|| ($mail_out['is_forward'] == True))
{
// attachments / parts have their own boundary preceeding them in their mime headers
// this is: "--"boundary
// all boundary strings are have 2 dashes "--" added to their begining
// and the FINAL boundary string (after all other parts) ALSO has
// 2 dashes "--" tacked on tho the end of it, very important !!
// the first or last \r\n is probably not necessary
$final_boundary = '--' .$mail_out['boundary'].'--'."\r\n";
if (!$this->msg2socket($socket,$final_boundary))
{
return false;
}
// another blank line
if (!$this->msg2socket($socket,"\r\n"))
{
return false;
}
}
// stop retaining the email copy, the message is over, only MTA closing handshake remainse
$this->retain_copy_ignore = True;
// DATA END - special string "DOTCRLF" signals the end of the body
if (!$this->msg2socket($socket,".\r\n"))
{
return false;
}
if (!$this->socket2msg($socket))
{
return false;
}
// QUIT
if (!$this->msg2socket($socket,"QUIT\r\n"))
{
return false;
}
if ($this->debug_fake_send)
{
echo '</pre><h3>end of Fake Send</h3></body></html>';
}
if (!$this->debug_fake_send)
{
do
{
$closing = $this->socket2msg($socket);
}
while ($closing);
}
return true;*/
}
|