29.8.2 回复或转发邮件

"Reply"、"Reply All"和"Forward"功能发送邮件的方法跟发送新邮件的方法相同。其不同之处在于,在将邮件发送表单显示给用户之前,系统已经自动填写好了某些域。回顾图29-8。我们要回复的消息正文已经用“>”符号缩进了,主题行以"Re:"为开始。同样,"Forward"和"Reply All"会预先填好接收者、主题行和缩进的消息正文。

完成这些操作的代码都是由index.php脚本的主体部分触发,如下所示:


case'reply-all':

//set cc as old cc line

if(!$imap){

$imap=open_mailbox($_SESSION['auth_user'],

$_SESSION['selected_account']);

}

if($imap){

$header=imap_header($imap,$messageid);

if($header->reply_toaddress){

$to=$header->reply_toaddress;

}else{

$to=$header->fromaddress;

}

$cc=$header->ccaddress;

$subject="Re:".$header->subject;

$body=add_quoting(stripslashes(imap_body($imap,$messageid)));

imap_close($imap);

display_new_message_form($_SESSION['auth_user'],

$to,$cc,$subject,$body);

}

break;

case'reply':

//set to address as reply-to or from of the current message

if(!$imap){

$imap=open_mailbox($_SESSION['auth_user'],

$_SESSION['selected_account']);

}

if($imap){

$header=imap_header($imap,$messageid);

if($header->reply_toaddress){

$to=$header->reply_toaddress;

}else{

$to=$header->fromaddress;

}

$subject="Re:".$header->subject;

$body=add_quoting(stripslashes(imap_body($imap,$messageid)));

imap_close($imap);

display_new_message_form($_SESSION['auth_user'],

$to,$cc,$subject,$body);

}

break;

case'forward':

//set message as quoted body of current message

if(!$imap){

$imap=open_mailbox($_SESSION['auth_user'],

$_SESSION['selected_account']);

}

if($imap){

$header=imap_header($imap,$messageid);

$body=add_quoting(stripslashes(imap_body($imap,$messageid)));

$subject="Fwd:".$header->subject;

imap_close($imap);

display_new_message_form($_SESSION['auth_user'],

$to,$cc,$subject,$body);

}

break;


可以看到,每一个选项都将建立相应的标题,必要时还会对标题进行格式化处理,然后再调用display_new_message_form()函数来建立表单。

这就是我们的Web邮件阅读系统的整个功能。