static public function replyToMail( ezcMail $mail, ezcMailAddress $from,
                                        $type = self::REPLY_SENDER, $subjectPrefix = "Re: ",
                                        $mailClass = "ezcMail" )
    {
        $reply = new $mailClass();
        $reply->from = $from;

        // To = Reply-To if set
        if ( $mail->getHeader( 'Reply-To' ) != '' )
        {
            $reply->to = ezcMailTools::parseEmailAddresses( $mail->getHeader( 'Reply-To' ) );
        }
        else  // Else To = From

        {
            $reply->to = array( $mail->from );
        }

        if ( $type == self::REPLY_ALL )
        {
            // Cc = Cc + To - your own address
            $cc = array();
            foreach ( $mail->to as $address )
            {
                if ( $address->email != $from->email )
                {
                    $cc[] = $address;
                }
            }
            foreach ( $mail->cc as $address )
            {
                if ( $address->email != $from->email )
                {
                    $cc[] = $address;
                }
            }
            $reply->cc = $cc;
        }

        $reply->subject = $subjectPrefix . $mail->subject;

        if ( $mail->getHeader( 'Message-Id' ) )
        {
            // In-Reply-To = Message-Id
            $reply->setHeader( 'In-Reply-To', $mail->getHeader( 'Message-ID' ) );

            // References = References . Message-Id
            if ( $mail->getHeader( 'References' ) != '' )
            {
                $reply->setHeader( 'References', $mail->getHeader( 'References' )
                                   . ' ' . $mail->getHeader( 'Message-ID' ) );
            }
            else
            {
                $reply->setHeader( 'References', $mail->getHeader( 'Message-ID' ) );
            }
        }
        else // original mail is borked. Let's support it anyway.
        {
            $reply->setHeader( 'References', $mail->getHeader( 'References' ) );
        }

        return $reply;
    }