aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2004-10-21 15:05:47 +0000
committerVincent Richard <[email protected]>2004-10-21 15:05:47 +0000
commit2949fb51f13e1236d5c161f02e1c2c8541100e9f (patch)
tree991edcf50483116ce83977a4d9e652de8c5328dc /examples
parentheader class unit tests added (diff)
downloadvmime-2949fb51f13e1236d5c161f02e1c2c8541100e9f.tar.gz
vmime-2949fb51f13e1236d5c161f02e1c2c8541100e9f.zip
Refactoring (see ChangeLog).
Diffstat (limited to 'examples')
-rw-r--r--examples/common.inc2
-rw-r--r--examples/example1.cpp26
-rw-r--r--examples/example2.cpp26
-rw-r--r--examples/example3.cpp25
-rw-r--r--examples/example4.cpp24
-rw-r--r--examples/example5.cpp11
-rw-r--r--examples/example6.cpp112
7 files changed, 129 insertions, 97 deletions
diff --git a/examples/common.inc b/examples/common.inc
index 6bef8037..ed9c4f4b 100644
--- a/examples/common.inc
+++ b/examples/common.inc
@@ -257,7 +257,7 @@ public:
gmt.tm_isdst = -1;
// Calculate the difference (in seconds)
- const vmime::datetime::comp_t diff = ::std::mktime(&local) - ::std::mktime(&gmt);
+ const int diff = ::std::mktime(&local) - ::std::mktime(&gmt);
// Return the date
return vmime::datetime(local.tm_year + 1900, local.tm_mon + 1, local.tm_mday,
diff --git a/examples/example1.cpp b/examples/example1.cpp
index 191a2adf..b639a4bc 100644
--- a/examples/example1.cpp
+++ b/examples/example1.cpp
@@ -45,14 +45,24 @@ int main()
vmime::messageBuilder mb;
// Fill in the basic fields
- mb.expeditor() = vmime::mailbox("[email protected]");
- mb.recipients().append(vmime::mailbox("[email protected]"));
- mb.blindCopyRecipients().append(vmime::mailbox("[email protected]"));
- mb.subject() = vmime::text("My first message generated with vmime::messageBuilder");
+ mb.setExpeditor(vmime::mailbox("[email protected]"));
+
+ vmime::addressList to;
+ to.appendAddress(new vmime::mailbox("[email protected]"));
+
+ mb.setRecipients(to);
+
+ vmime::addressList bcc;
+ bcc.appendAddress(new vmime::mailbox("[email protected]"));
+
+ mb.setBlindCopyRecipients(bcc);
+
+ mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder"));
// Message body
- mb.textPart().text() = "I'm writing this short text to test message construction " \
- "using the vmime::messageBuilder component.";
+ mb.getTextPart()->setText(vmime::contentHandler(
+ "I'm writing this short text to test message construction " \
+ "using the vmime::messageBuilder component."));
// Construction
vmime::message* msg = mb.construct();
@@ -61,7 +71,7 @@ int main()
std::cout << "Generated message:" << std::endl;
std::cout << "==================" << std::endl;
- vmime::outputStreamAdapter out(std::cout);
+ vmime::utility::outputStreamAdapter out(std::cout);
msg->generate(out);
// Destruction
@@ -77,7 +87,7 @@ int main()
catch (std::exception& e)
{
std::cout << "std::exception: " << e.what() << std::endl;
- throw;
+ //throw;
}
std::cout << std::endl;
diff --git a/examples/example2.cpp b/examples/example2.cpp
index 183b6d02..6e7f81c6 100644
--- a/examples/example2.cpp
+++ b/examples/example2.cpp
@@ -45,14 +45,24 @@ int main()
vmime::messageBuilder mb;
// Fill in the basic fields
- mb.expeditor() = vmime::mailbox("[email protected]");
- mb.recipients().append(vmime::mailbox("[email protected]"));
- mb.blindCopyRecipients().append(vmime::mailbox("[email protected]"));
- mb.subject() = vmime::text("My first message generated with vmime::messageBuilder");
+ mb.setExpeditor(vmime::mailbox("[email protected]"));
+
+ vmime::addressList to;
+ to.appendAddress(new vmime::mailbox("[email protected]"));
+
+ mb.setRecipients(to);
+
+ vmime::addressList bcc;
+ bcc.appendAddress(new vmime::mailbox("[email protected]"));
+
+ mb.setBlindCopyRecipients(bcc);
+
+ mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder"));
// Message body
- mb.textPart().text() = "I'm writing this short text to test message construction " \
- "with attachment, using the vmime::messageBuilder component.";
+ mb.getTextPart()->setText(vmime::contentHandler(
+ "I'm writing this short text to test message construction " \
+ "with attachment, using the vmime::messageBuilder component."));
// Adding an attachment
vmime::fileAttachment* a = new vmime::fileAttachment
@@ -62,8 +72,8 @@ int main()
vmime::text("My first attachment") // description
);
- a->fileInfo().setFilename("example2.cpp");
- a->fileInfo().setCreationDate(vmime::datetime("30 Apr 2003 14:30:00 +0200"));
+ a->getFileInfo().setFilename("example2.cpp");
+ a->getFileInfo().setCreationDate(vmime::datetime("30 Apr 2003 14:30:00 +0200"));
mb.attach(a);
diff --git a/examples/example3.cpp b/examples/example3.cpp
index c8cc0f2f..d2b41754 100644
--- a/examples/example3.cpp
+++ b/examples/example3.cpp
@@ -45,10 +45,19 @@ int main()
vmime::messageBuilder mb;
// Fill in the basic fields
- mb.expeditor() = vmime::mailbox("[email protected]");
- mb.recipients().append(vmime::mailbox("[email protected]"));
- mb.blindCopyRecipients().append(vmime::mailbox("[email protected]"));
- mb.subject() = vmime::text("My first message generated with vmime::messageBuilder");
+ mb.setExpeditor(vmime::mailbox("[email protected]"));
+
+ vmime::addressList to;
+ to.appendAddress(new vmime::mailbox("[email protected]"));
+
+ mb.setRecipients(to);
+
+ vmime::addressList bcc;
+ bcc.appendAddress(new vmime::mailbox("[email protected]"));
+
+ mb.setBlindCopyRecipients(bcc);
+
+ mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder"));
// Set the content-type to "text/html"
mb.constructTextPart(vmime::mediaType
@@ -56,16 +65,16 @@ int main()
// Fill in the text part: the message is available in two formats: HTML and plain text.
// HTML text part also includes an inline image (embedded into the message).
- vmime::htmlTextPart& textPart = dynamic_cast<vmime::htmlTextPart&>(mb.textPart());
+ vmime::htmlTextPart& textPart = dynamic_cast<vmime::htmlTextPart&>(*mb.getTextPart());
// -- embed an image (the returned "CID" (content identifier) is used to reference
// -- the image into HTML content).
- vmime::string cid = textPart.embeddedObjects.add("<...IMAGE DATA...>",
+ vmime::string cid = textPart.addObject("<...IMAGE DATA...>",
vmime::mediaType(vmime::mediaTypes::IMAGE, vmime::mediaTypes::IMAGE_JPEG));
// -- message text
- textPart.text() = vmime::string("This is the <b>HTML text</b>.<br/><img src=\"") + cid + vmime::string("\"/>");
- textPart.plainText() = vmime::string("This is the plain text (without HTML formatting).");
+ textPart.setText(vmime::contentHandler(vmime::string("This is the <b>HTML text</b>.<br/><img src=\"") + cid + vmime::string("\"/>")));
+ textPart.setPlainText(vmime::contentHandler(vmime::string("This is the plain text (without HTML formatting).")));
// Construction
vmime::message* msg = mb.construct();
diff --git a/examples/example4.cpp b/examples/example4.cpp
index 164e4be9..605452fe 100644
--- a/examples/example4.cpp
+++ b/examples/example4.cpp
@@ -44,28 +44,28 @@ int main()
vmime::messageParser mp("<...MIME message content...>");
// Enumerate text parts
- for (std::vector <vmime::textPart*>::const_iterator i = mp.textParts().begin() ;
- i != mp.textParts().end() ; ++i)
+ for (int i = 0 ; i < mp.getTextPartCount() ; ++i)
{
- const vmime::textPart& part = **i;
+ const vmime::textPart& part = *mp.getTextPartAt(i);
// Output content-type of the part
- std::cout << part.type().generate() << std::endl;
+ std::cout << part.getType().generate() << std::endl;
// text/html
- if (part.type().subType() == vmime::mediaTypes::TEXT_HTML)
+ if (part.getType().getSubType() == vmime::mediaTypes::TEXT_HTML)
{
const vmime::htmlTextPart& hp = dynamic_cast<const vmime::htmlTextPart&>(part);
- // HTML text is in "hp.text()"
- // Corresponding plain text is in "hp.plainText()"
+ // HTML text is in "hp.getText()"
+ // Corresponding plain text is in "hp.getPlainText()"
// Enumerate embedded objects (eg. images)
- for (vmime::htmlTextPart::const_iterator i = hp.embeddedObjects.begin() ;
- i != hp.embeddedObjects.end() ; ++i)
+ for (int j = 0 ; j < hp.getObjectCount() ; ++j)
{
- // Identifier (content-id or content-location) is in "(*i).id()"
- // Object data is in "(*i).data()"
+ const vmime::htmlTextPart::embeddedObject& obj = *hp.getObjectAt(j);
+
+ // Identifier (content-id or content-location) is in "obj.getId()"
+ // Object data is in "obj.getData()"
}
}
// text/plain
@@ -73,7 +73,7 @@ int main()
{
const vmime::textPart& tp = dynamic_cast<const vmime::textPart&>(part);
- // Text is in "tp.text()"
+ // Text is in "tp.getText()"
}
}
}
diff --git a/examples/example5.cpp b/examples/example5.cpp
index a36d8c09..e5a7c93b 100644
--- a/examples/example5.cpp
+++ b/examples/example5.cpp
@@ -45,12 +45,13 @@ int main()
vmime::messageParser mp("<...MIME message content...>");
// Enumerate attachments
- for (std::vector <vmime::attachment*>::const_iterator i = mp.attachments().begin() ;
- i != mp.attachments().end() ; ++i)
+ for (int i = 0 ; i < mp.getAttachmentCount() ; ++i)
{
- // Media type (content type) is in "(*i).type()"
- // Description is in "(*i).description()"
- // Data is in "(*i).data()"
+ const vmime::attachment& att = *mp.getAttachmentAt(i);
+
+ // Media type (content type) is in "att.getType()"
+ // Description is in "att.getDescription()"
+ // Data is in "att.getData()"
}
}
// VMime exception
diff --git a/examples/example6.cpp b/examples/example6.cpp
index 6bea365e..78fe0f3d 100644
--- a/examples/example6.cpp
+++ b/examples/example6.cpp
@@ -49,19 +49,19 @@ class my_auth : public vmime::messaging::authenticator
void printStructure(const vmime::messaging::structure& s, int level = 0)
{
- for (int i = 1 ; i <= s.count() ; ++i)
+ for (int i = 1 ; i <= s.getCount() ; ++i)
{
const vmime::messaging::part& part = s[i];
for (int j = 0 ; j < level * 2 ; ++j)
std::cout << " ";
- std::cout << part.number() << ". "
- << part.type().generate()
- << " [" << part.size() << " byte(s)]"
+ std::cout << part.getNumber() << ". "
+ << part.getType().generate()
+ << " [" << part.getSize() << " byte(s)]"
<< std::endl;
- printStructure(part.structure(), level + 1);
+ printStructure(part.getStructure(), level + 1);
}
}
@@ -76,22 +76,23 @@ int main()
// Test the new enumeration system for encoders
//
-#if 0
+#if 1
vmime::encoderFactory* ef = vmime::encoderFactory::getInstance();
std::cout << "Available encoders:" << std::endl;
- for (vmime::encoderFactory::iterator it = ef->begin() ;
- it != ef->end() ; ++it)
+ for (int i = 0 ; i < ef->getEncoderCount() ; ++i)
{
- std::cout << " * " << (*it).name() << std::endl;
+ const vmime::encoderFactory::registeredEncoder& enc = *ef->getEncoderAt(i);
- vmime::encoder* e = (*it).create();
+ std::cout << " * " << enc.getName() << std::endl;
- std::vector <vmime::string> props = e->availableProperties();
+ vmime::encoder* e = enc.create();
- for (std::vector <vmime::string>::const_iterator it2 = props.begin() ; it2 != props.end() ; ++it2)
- std::cout << " - " << *it2 << std::endl;
+ std::vector <vmime::string> props = e->getAvailableProperties();
+
+ for (std::vector <vmime::string>::const_iterator it = props.begin() ; it != props.end() ; ++it)
+ std::cout << " - " << *it << std::endl;
delete (e);
}
@@ -108,21 +109,22 @@ int main()
std::cout << "Available messaging services:" << std::endl;
- for (vmime::messaging::serviceFactory::const_iterator it = sf->begin() ;
- it != sf->end() ; ++it)
+ for (int i = 0 ; i < sf->getServiceCount() ; ++i)
{
- std::cout << " * " << (*it).name() << " (" << (*it).infos().defaultPort() << ")" << std::endl;
+ const vmime::messaging::serviceFactory::registeredService& serv = *sf->getServiceAt(i);
+
+ std::cout << " * " << serv.getName() << " (" << serv.getInfos().getDefaultPort() << ")" << std::endl;
- std::vector <vmime::string> props = (*it).infos().availableProperties();
+ std::vector <vmime::string> props = serv.getInfos().getAvailableProperties();
- for (std::vector <vmime::string>::const_iterator it2 = props.begin() ; it2 != props.end() ; ++it2)
- std::cout << " - " << (*it).infos().propertyPrefix() + *it2 << std::endl;
+ for (std::vector <vmime::string>::const_iterator it = props.begin() ; it != props.end() ; ++it)
+ std::cout << " - " << serv.getInfos().getPropertyPrefix() + *it << std::endl;
}
#endif
vmime::messaging::session sess;
- sess.properties()["store.protocol"] = "imap";
- sess.properties()["transport.protocol"] = "smtp";
+ sess.getProperties()["store.protocol"] = "imap";
+ sess.getProperties()["transport.protocol"] = "smtp";
my_auth auth;
@@ -136,12 +138,12 @@ int main()
// Transport protocol configuration
vmime::messaging::transport* tr = sess.getTransport();
- //sess.properties()[tr->infos().propertyPrefix() + "auth.username"] = "username";
- //sess.properties()[tr->infos().propertyPrefix() + "auth.password"] = "password";
+ //sess.getProperties()[tr->getInfos().getPropertyPrefix() + "auth.username"] = "username";
+ //sess.getProperties()[tr->getInfos().getPropertyPrefix() + "auth.password"] = "password";
- sess.properties()[tr->infos().propertyPrefix() + "server.address"] = "smtp.mydomain.com";
+ sess.getProperties()[tr->getInfos().getPropertyPrefix() + "server.address"] = "smtp.mydomain.com";
- //sess.properties()[tr->infos().propertyPrefix() + "options.need-authentification"] = true;
+ //sess.getProperties()[tr->getInfos().getPropertyPrefix() + "options.need-authentification"] = true;
// Connection
tr->connect();
@@ -151,8 +153,8 @@ int main()
// Recipients list
vmime::mailboxList to;
- to.append(vmime::mailbox("[email protected]"));
- to.append(vmime::mailbox("[email protected]"));
+ to.appendMailbox(new vmime::mailbox("[email protected]"));
+ to.appendMailbox(new vmime::mailbox("[email protected]"));
std::istringstream iss("[MESSAGE DATA: HEADER + BODY]");
tr->send(from, to, iss);
@@ -176,15 +178,15 @@ int main()
vmime::messaging::store* st = sess.getStore(&auth);
// Store protocol configuration
- //sess.properties()[st->infos().propertyPrefix() + "auth.username"] = "username";
- //sess.properties()[st->infos().propertyPrefix() + "auth.password"] = "password";
+ //sess.getProperties()[st->getInfos().getPropertyPrefix() + "auth.username"] = "username";
+ //sess.getProperties()[st->getInfos().getPropertyPrefix() + "auth.password"] = "password";
- sess.properties()[st->infos().propertyPrefix() + "server.address"] = "imap.mydomain.com";
- //sess.properties()[st->infos().propertyPrefix() + "server.port"] = 110;
- //sess.properties()[st->infos().propertyPrefix() + "server.socket-factory"] = "default";
+ sess.getProperties()[st->getInfos().getPropertyPrefix() + "server.address"] = "imap.mydomain.com";
+ //sess.getProperties()[st->getInfos().getPropertyPrefix() + "server.port"] = 110;
+ //sess.getProperties()[st->getInfos().getPropertyPrefix() + "server.socket-factory"] = "default";
- //sess.properties()[st->infos().propertyPrefix() + "options.apop"] = false;
- //sess.properties()[st->infos().propertyPrefix() + "options.apop.fallback"] = true;
+ //sess.getProperties()[st->getInfos().getPropertyPrefix() + "options.apop"] = false;
+ //sess.getProperties()[st->getInfos().getPropertyPrefix() + "options.apop.fallback"] = true;
// Connection
st->connect();
@@ -205,7 +207,7 @@ int main()
// To retrieve the whole message
std::ostringstream oss;
- vmime::outputStreamAdapter out(oss);
+ vmime::utility::outputStreamAdapter out(oss);
m->extract(out);
@@ -223,55 +225,55 @@ int main()
std::cout << "STRUCTURE:" << std::endl;
std::cout << "==========" << std::endl;
- printStructure(m->structure());
+ printStructure(m->getStructure());
std::cout << std::endl;
- std::cout << "Size = " << m->size() << " byte(s)" << std::endl;
- std::cout << "UID = " << m->uniqueId() << std::endl;
+ std::cout << "Size = " << m->getSize() << " byte(s)" << std::endl;
+ std::cout << "UID = " << m->getUniqueId() << std::endl;
std::cout << std::endl;
std::cout << "ENVELOPE:" << std::endl;
std::cout << "=========" << std::endl;
- try { std::cout << m->header().fields.From().generate() << std::endl; } catch (...) { }
- try { std::cout << m->header().fields.To().generate() << std::endl; } catch (...) { }
- try { std::cout << m->header().fields.Date().generate() << std::endl; } catch (...) { }
- try { std::cout << m->header().fields.Subject().generate() << std::endl; } catch (...) { }
+ try { std::cout << m->getHeader().From().generate() << std::endl; } catch (...) { }
+ try { std::cout << m->getHeader().To().generate() << std::endl; } catch (...) { }
+ try { std::cout << m->getHeader().Date().generate() << std::endl; } catch (...) { }
+ try { std::cout << m->getHeader().Subject().generate() << std::endl; } catch (...) { }
std::cout << std::endl;
std::cout << "FULL HEADER:" << std::endl;
std::cout << "============" << std::endl;
- std::cout << m->header().generate() << std::endl;
+ std::cout << m->getHeader().generate() << std::endl;
std::cout << std::endl;
std::cout << "=========================================================" << std::endl;
- vmime::outputStreamAdapter out2(std::cout);
- m->extractPart(m->structure()[1][2][1], out2, NULL); //, 0, 10);
+ vmime::utility::outputStreamAdapter out2(std::cout);
+ m->extractPart(m->getStructure()[1][2][1], out2, NULL); //, 0, 10);
std::cout << "=========================================================" << std::endl;
std::cout << std::endl;
std::cout << "=========================================================" << std::endl;
- m->fetchPartHeader(m->structure()[1][2][1]);
+ m->fetchPartHeader(m->getStructure()[1][2][1]);
- std::cout << m->structure()[1][2][1].header().generate() << std::endl;
+ std::cout << m->getStructure()[1][2][1].getHeader().generate() << std::endl;
std::cout << "=========================================================" << std::endl;
// Flags manipulation
- std::cout << "Flags = " << m->flags() << std::endl;
+ std::cout << "Flags = " << m->getFlags() << std::endl;
m->setFlags(vmime::messaging::message::FLAG_REPLIED, vmime::messaging::message::FLAG_MODE_ADD);
- std::cout << "Flags = " << m->flags() << std::endl;
+ std::cout << "Flags = " << m->getFlags() << std::endl;
m->setFlags(vmime::messaging::message::FLAG_REPLIED, vmime::messaging::message::FLAG_MODE_REMOVE);
- std::cout << "Flags = " << m->flags() << std::endl;
+ std::cout << "Flags = " << m->getFlags() << std::endl;
- f->setMessageFlags(m->number(), m->number(), vmime::messaging::message::FLAG_REPLIED, vmime::messaging::message::FLAG_MODE_ADD);
- std::cout << "Flags = " << m->flags() << std::endl;
- f->setMessageFlags(m->number(), m->number(), vmime::messaging::message::FLAG_REPLIED, vmime::messaging::message::FLAG_MODE_REMOVE);
- std::cout << "Flags = " << m->flags() << std::endl;
+ f->setMessageFlags(m->getNumber(), m->getNumber(), vmime::messaging::message::FLAG_REPLIED, vmime::messaging::message::FLAG_MODE_ADD);
+ std::cout << "Flags = " << m->getFlags() << std::endl;
+ f->setMessageFlags(m->getNumber(), m->getNumber(), vmime::messaging::message::FLAG_REPLIED, vmime::messaging::message::FLAG_MODE_REMOVE);
+ std::cout << "Flags = " << m->getFlags() << std::endl;
std::cout << "=========================================================" << std::endl;
@@ -312,7 +314,7 @@ int main()
if (!g->exists())
g->create(vmime::messaging::folder::TYPE_CONTAINS_MESSAGES);
- f->copyMessages(g->fullPath());
+ f->copyMessages(g->getFullPath());
delete (g);
}