Issues

ZF-1626: Add methods for removing or replacing headers

Description

[reported by tim weyand http://nabble.com/Zend_Mail---Zend_Mail_Transport_…]

Feature "Wish" : Could "delTo", "delCc", "delBcc", "delSubject", "delFrom" methods be added to Zend_Mail?

Comments

Assigned to Nico.

Marking fix version as unknown. Please set fix version when this issue is resolved.

In my opinion, it should be possible to delete settings, which have been set by the script.

["delTo", "delCc", "delBcc" (name sugesstion)]

After an email was send, in most cases it is neccessary to clear the receipient list. Currently you can add "infinite" receipients to your reseipient list, but you can not delete any.

I think most people wouldn't need to delete a specific email adress out of the To,Cc,Bcc list, so i would sugesst that an delTo would delete alle receipients in the "To receipient list".

Alternatively an "delReceipientList" would be easier to implement, but was in the past declined http://framework.zend.com/issues/browse/ZF-30.

I wrote an class which extends Zend_Mail, in this class i implemented a "delReceipientList".

public function delReceipientList() { $this->_to=array(); $this->_recipients=array(); if (isset($this->_headers['To'])) unset($this->_headers['To']); if (isset($this->_headers['Cc'])) unset($this->_headers['Cc']); if (isset($this->_headers['Bcc'])) unset($this->_headers['Bcc']); }

[delFrom] In some cases you change not only the receipient, but also the sender. This case is for example a greeting card, a news article which you want to send a friend ...

Currently you can set the from header only ones, otherwise you get an exception. Which is actually good, but there should be an method to delete the From Header.

Maybe something like this :

public function delFrom() { if (!is_null($this->_from)) $this->_from=null; if (isset($this->_headers['From'])) unset($this->_headers['From']); }

[delSubject] The same as the from header, you can only set the subject line ones - otherwise you get an exception. This is not that important for myself, but for the purpose of completion it should be implemented as well.

Maybe something like this :

public function delSubject() { if (!is_null($this->_subject)) $this->_subject=null; if (isset($this->_headers["Subject"])) unset($this->_headers["Subject"]); }

I hope this helps.

regards, Tim

Implemented in SVN r13499.

I added Following functions

_clearHeader($headerName) clearRecipients() clearFrom() clearReturnPath() clearSubject() clearDate()