writemail.cpp

来自「Qtopia下的邮件处理程序」· C++ 代码 · 共 1,183 行 · 第 1/3 页

CPP
1,183 行
字号
}bool WriteMail::buildMail(){    // TODO - should check formatting of recipients?    /*  if( !isComplete() )  {  qDebug("BUG : build mail called on incomplete mail");  return false;}    */  m_composerInterface->getContent( mail );#ifdef QTOPIA_PHONE    m_detailsPage->getDetails( mail );#endif    mail.setDateTime( QDateTime::currentDateTime() );    //FIXME : DetailsPage::getDetails should do this, but needs account list    QString fromName, fromEmail = mail.from();    QListIterator<MailAccount*> itAccount = accountList->accountIterator();    while (itAccount.hasNext())    {      MailAccount* current = itAccount.next();      if ( current->emailAddress() == fromEmail ||           current->userName().toLower() == fromEmail.toLower() )      {        fromName = current->userName();        fromEmail = current->emailAddress();        break;      }    }    mail.setFrom( createFrom( fromName, fromEmail ) );    mail.setStatus(EFlag_Outgoing | EFlag_Downloaded, true);    return true;}/*  TODO: connect this method to the input widgets so we can actually know whether    the mail was changed or not */bool WriteMail::changed() const{  if( !m_composerInterface || !m_composerInterface->hasContent() )  {    return false;  }  return true;}// sharp 1839 to herestatic void checkOutlookString(QString &str){  int  pos = 0;  int  newPos;  QString  oneAddr;  QStringList  newStr;  if (str.indexOf(";") == -1){        // not Outlook style    return;  }  while ((newPos = str.indexOf(";", pos)) != -1){    if (newPos > pos + 1){            // found some string      oneAddr = str.mid(pos, newPos-pos);      if (oneAddr.indexOf("@") != -1){                // not Outlook comment        newStr.append(oneAddr);      }    }    if ( (pos = newPos + 1) >= str.length() ){      break;    }  }  str = newStr.join(", ");}void WriteMail::attach( const QContent &dl ){  if( m_composerInterface )    m_composerInterface->attach( dl );  else    qDebug("WriteMail::attach called with no composer interface present.");}void WriteMail::attach( const QString &fileName ){  if( m_composerInterface )    m_composerInterface->attach( fileName );  else    qDebug("WriteMail::attach called with no composer interface present.");}// type 1 = reply, 2 = reply all, 3 = forwardvoid WriteMail::reply(const Email &replyMail, int type){  int pos;    // work out the kind of mail to response    // type of reply depends on the type of message    // a reply to an mms is just a new mms message with the sender as recipient    // a reply to an sms is a new sms message with the sender as recipient  mail = replyMail;  QUuid id;  mail.setUuid( id );  QString fromEmail = mail.fromEmail();  QString fromName = mail.fromName();  QString fromBody = mail.plainTextBody();  newMail(#ifdef QTOPIA_PHONE      ComposerFactory::defaultInterface( replyMail )#endif         );#ifdef QTOPIA_PHONE    if( replyMail.type() == MailMessage::SMS ){    // SMS  if (!fromEmail.isEmpty())  {    QString from = fromEmail;    if( from.right( 4 ) == "@sms" ) {      int len = replyMail.fromEmail().length();      from = replyMail.fromEmail().left( len - 4 );    }    m_detailsPage->setTo( from );  }} else if (replyMail.type() == MailMessage::MMS) {  if (type == 3) {    if (replyMail.subject().left(4).toLower() != "fwd:"        && replyMail.subject().left(4).toLower() != "fw:") {      m_detailsPage->setSubject("Fwd: " + replyMail.subject() );        } else {          m_detailsPage->setSubject( replyMail.subject() );        }        m_composerInterface->setMailMessage( mail );        detailsStage();  } else {    m_detailsPage->setTo(replyMail.fromEmail());    if (replyMail.subject().left(3).toLower() != "re:")      m_detailsPage->setSubject("Re: " + replyMail.subject());    else      m_detailsPage->setSubject(replyMail.subject());    if (type == 2) {      QStringList all = replyMail.to();      all += replyMail.cc();      QString cc = all.join(", ");      checkOutlookString( cc );      m_detailsPage->setCc( cc );    }  }}    else#endif          if( replyMail.type() ==  MailMessage::Email ){        // EMAIL  if ( type == 3 )  {    if ( replyMail.subject().left(4).toLower() != "fwd:")#ifdef QTOPIA_PHONE          m_detailsPage#else          m_composerInterface#endif          ->setSubject("Fwd: " + replyMail.subject() );    else#ifdef QTOPIA_PHONE          m_detailsPage#else          m_composerInterface#endif          ->setSubject( replyMail.subject() );  }  else  {    if( replyMail.subject().left(3).toLower() != "re:" )#ifdef QTOPIA_PHONE          m_detailsPage#else          m_composerInterface#endif          ->setSubject( "Re: " + replyMail.subject() );    else#ifdef QTOPIA_PHONE          m_detailsPage#else          m_composerInterface#endif          ->setSubject( replyMail.subject() );        mail.removeAllMessageParts();    QString str;        if ( replyMail.replyTo().isEmpty() ) {      str = replyMail.fromEmail();    } else {      str = replyMail.replyTo();      mail.setReplyTo( "" );    }        checkOutlookString(str);#ifdef QTOPIA_PHONE        m_detailsPage->setTo( str );#else        m_composerInterface->setTo( str );#endif        mail.setInReplyTo( mail.messageId() );        if ( type == 2 ) {  //reply all          QStringList all = replyMail.to();          all += replyMail.cc();          QString cc = all.join(", ");          checkOutlookString( cc );    #ifdef QTOPIA_PHONE        m_detailsPage#else        m_composerInterface#endif        ->setCc( cc );        }  }  QString str;  if ( type == 3 ) {    str = "\n------------ Forwarded Message ------------\n";    str += "Date: " + replyMail.dateString() + "\n";    str += "From: " + replyMail.fromName() + "<" + replyMail.fromEmail() + ">\n";    str += "To: " + replyMail.to().join(", ") + "\n";    str += "Subject: " + replyMail.subject() + "\n";    str += "\n" + replyMail.plainTextBody();  } else {    if ( !replyMail.dateTime().isNull() ) {      str = "\nOn " + Email::formattedDateTimeString(replyMail.dateTime()) + ", " + fromName + " wrote:\n> ";    } else {      str = "\nOn " + replyMail.dateString() + ", " + replyMail.fromName() + " wrote:\n> ";    }    pos = str.length();    str += replyMail.plainTextBody();    while (pos != -1) {      pos = str.indexOf('\n', pos);      if (pos != -1)        str.insert(++pos, "> ");    }  }  mail.setPlainTextBody( str );  mail.setFrom("");#ifdef QTOPIA_PHONE    if( m_composerInterface->inherits( "TextComposerInterface" ) ){  TextComposerInterface *iface = (TextComposerInterface *)m_composerInterface;  iface->setText( fromBody );}    else{  qWarning("Don't know how to set text of unknown email composer type.");}#else    m_composerInterface->setText( fromBody );#endif}    //accountId stored in mail, but email address used for selecting    //account, so loop through and find the matching account    QListIterator<MailAccount*> it = accountList->accountIterator();    while (it.hasNext()) {      MailAccount* current = it.next();      if ( current->id() == mail.fromAccount() ) {#ifdef QTOPIA_PHONE        m_detailsPage#else        m_composerInterface#endif        ->setFrom( current->emailAddress() );        break;      }    }    // ugh. we need to do this everywhere    hasMessageChanged = false;}void WriteMail::modify(Email *previousMail){  QString recipients = "";  newMail(#ifdef QTOPIA_PHONE      ComposerFactory::defaultInterface( previousMail->type() )#endif         );  mail.setUuid( previousMail->uuid() );  mail.setFrom( previousMail->from() );#ifdef QTOPIA_PHONE    m_detailsPage#else    m_composerInterface#endif    ->setFrom( previousMail->fromEmail() );#ifdef QTOPIA_PHONE    m_detailsPage#else    m_composerInterface#endif    ->setSubject( previousMail->subject() );    m_composerInterface#ifdef QTOPIA_PHONE        ->setMailMessage( *previousMail );#else    ->setText( previousMail->plainTextBody() );#endif#ifdef QTOPIA_PHONE    m_detailsPage->setTo( previousMail->to().join(", ") );    m_detailsPage->setCc( previousMail->cc().join(", ") );    m_detailsPage->setBcc( previousMail->bcc().join(", ") );#else    m_composerInterface->setTo( previousMail->to().join(", ") );    m_composerInterface->setCc( previousMail->cc().join(", ") );    m_composerInterface->setBcc( previousMail->bcc().join(", ") );    // Restore attachments    for ( int i = 0; i < (int)previousMail->messagePartCount(); i++ ) {      MailMessagePart &part = previousMail->messagePartAt( i );      previousMail->validateFile( part );      attach( part.storedFilename() );    }#endif    // ugh. we need to do this everywhere    hasMessageChanged = false;}void WriteMail::setRecipient(const QString &recipient){#ifdef QTOPIA_PHONE    m_detailsPage#else    m_composerInterface#endif    ->setTo( recipient );}void WriteMail::setBody(const QString &text){#ifdef QTOPIA_PHONE    if( !m_composerInterface )    return;    if( m_composerInterface->type() == MailMessage::MMS )      return;    if( m_composerInterface->inherits( "TextComposerInterface" ) )    {      TextComposerInterface *iface = (TextComposerInterface *)m_composerInterface;      iface->setText( text );    }    else    {      qWarning("Can't set body of mail with unknown composer interface.");    }#else    m_composerInterface->setText( text );#endif}bool WriteMail::hasContent(){    // Be conservative when returning false, which means the message can    // be discarded without user confirmation.    if( !m_composerInterface )	return true;    return m_composerInterface->hasContent();}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?