int main() { Regexx rxx; try { // 1 - Replacing strings with atom substitution: std::cout << "1: "; std::cout << rxx.replace("I love expensive software!","expensive (soft[a-z]*)", "free %0"); std::cout << std::endl; // 2 - Atom retrieving: std::cout << "2: "; rxx.exec("http://distro.conectiva.com/projetos/32/","http://([-1-9a-zA-Z\\.]*)/"); if(rxx.match.size() > 0 && rxx.match[0].atom.size() > 0) std::cout << "Regexx's host is " << rxx.match[0].atom[0] << "." << std::endl; else std::cout << "Oops, no hosts found!" << std::endl; // 3 - Patern matching: std::cout << "3: "; if(rxx.exec("*****@*****.**",".+@gnu\\.org$")) std::cout << "Yeah! It's from gnu.org!" << std::endl; else std::cout << "No, it's not from gnu.org." << std::endl; // 4 - Counting occurrences: std::cout << "4: "; std::cout << "There are " << rxx.exec("There are n 'a's in this phrase.", "a",Regexx::global|Regexx::nomatch) << " 'a's in this phrase." << std::endl; // 5 - Removing HTML tags: std::cout << "5: "; std::cout << rxx.replace("<B>Please, <STRIKE>no</STRIKE> tags.</B>", "</?[a-z]+( [^>]*)*>", "", Regexx::global|Regexx::nocase|Regexx::study); std::cout << std::endl; // 6 - Customizing replaces std::cout << "6: "; std::cout << rxx.replacef("Turn your free software into expensive software.", "free|expensive", invert, Regexx::global); std::cout << std::endl; // 7 - One-line regular expressions using constructors std::cout << "7: "; if(Regexx("Using constructor!","constructor")) std::cout << "I've found the 'constructor' word!" << std::endl; else std::cout << "I haven't found the 'constructor' word!" << std::endl; } catch(Regexx::CompileException &e) { std::cerr << e.message() << std::endl; } return 0; }
/*------------------------------------------------------------------------------*\ StateSendMails() - sends the queued mails to the server (invokes MAIL, RCPT and DATA-commands) - depending on the handling of Bcc-recipients, each mail is only sent to the server once (SpecialHeaderForEachBcc=false) or each mail is being sent once for the standard recipients (To, Cc) plus a personalized version for each Bcc-recipient (SpecialHeaderForEachBcc=true) \*------------------------------------------------------------------------------*/ void BmSmtp::StateSendMails() { mMailCount = mQueuedRefVect.size(); mMsgTotalSize = 0; vector<BmRef<BmMailRef> > mailRefs; BmRef<BmMail> mail; for( int32 i=0; i<mMailCount; ++i) { mailRefs.push_back(BmMailRef::CreateInstance( mQueuedRefVect[i])); if (mailRefs[i] && mailRefs[i]->IsValid()) mMsgTotalSize += int32(mailRefs[i]->Size()); } Regexx rx; mCurrMailNr = 1; for( int32 i=0; i<mMailCount; ++i, ++mCurrMailNr) { if (!mailRefs[i] || !mailRefs[i]->IsValid()) { BM_LOGERR( BmString("SendMails(): mail no. ") << i+1 << " can't be found, skipping it."); continue; } BmRef<BmMail> mail = BmMail::CreateInstance( mailRefs[i].Get()); if (mail) { if (mail->InitCheck() != B_OK) mail->StartJobInThisThread( BmMail::BM_READ_MAIL_JOB); if (mail->InitCheck() != B_OK) { BM_LOGERR( BmString("SendMails(): mail no. ") << i+1 << " can't be read, skipping it."); continue; } } mCurrMailSize = mail->RawText().Length(); BmString headerText = mail->HeaderText(); if (!mail->Header()->IsFieldEmpty(BM_FIELD_RESENT_BCC)) { // remove RESENT-BCC-header from mailtext... headerText = rx.replace( headerText, "^Resent-Bcc:\\s*.+?\\r\\n(\\s+.*?\\r\\n)*", "", Regexx::newline ); } if (!mail->Header()->IsFieldEmpty(BM_FIELD_BCC)) { // remove BCC-header from mailtext... headerText = rx.replace( headerText, "^Bcc:\\s*.+?\\r\\n(\\s+.*?\\r\\n)*", "", Regexx::newline ); } try { BmRcptSet rcptSet; if (ThePrefs->GetBool("SpecialHeaderForEachBcc")) { if (HasStdRcpts( mail.Get(), rcptSet)) { Mail( mail.Get()); Rcpt( rcptSet); Data( mail.Get(), headerText); } BccRcpt( mail.Get(), true, headerText); } else { Mail( mail.Get()); if (HasStdRcpts( mail.Get(), rcptSet)) Rcpt( rcptSet); BccRcpt( mail.Get(), false, headerText); Data( mail.Get(), headerText); } if (ShouldContinue()) { mail->MarkAs( BM_MAIL_STATUS_SENT); mail->ApplyOutboundFilters(); // give filters a chance that check for 'Sent'-status... } } catch( BM_runtime_error &err) { // a problem occurred, we tell the user: BM_LOGERR( BmString("SendMails(): mail no. ") << i+1 << " couldn't be sent.\n\nError:\n" << err.what()); mail->MarkAs( BM_MAIL_STATUS_ERROR); // mark mail as ERROR since it couldn't be sent SendCommand("RSET"); // reset SMTP-state in order to start afresh with next mail } } mCurrMailSize = 0; mCurrMailNr = 0; }