diff options
author | Vincent Richard <[email protected]> | 2018-09-05 21:54:48 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2018-09-05 21:54:48 +0000 |
commit | b55bdc9c0bb68236aa2de0a8eaec9f4c80cc2769 (patch) | |
tree | efa18d623d3bc67c41d643aae145c16aa8f1006d /examples/example4.cpp | |
parent | Merge pull request #198 from xguerin/master (diff) | |
download | vmime-b55bdc9c0bb68236aa2de0a8eaec9f4c80cc2769.tar.gz vmime-b55bdc9c0bb68236aa2de0a8eaec9f4c80cc2769.zip |
Code style and clarity.
Diffstat (limited to 'examples/example4.cpp')
-rw-r--r-- | examples/example4.cpp | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/examples/example4.cpp b/examples/example4.cpp index 1e0d6657..4d50c2e4 100644 --- a/examples/example4.cpp +++ b/examples/example4.cpp @@ -1,6 +1,6 @@ // // VMime library (http://www.vmime.org) -// Copyright (C) 2002-2013 Vincent Richard <[email protected]> +// Copyright (C) 2002 Vincent Richard <[email protected]> // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -39,71 +39,70 @@ #include "vmime/platforms/posix/posixHandler.hpp" -int main() -{ +int main() { + std::cout << std::endl; // Set the global C and C++ locale to the user-configured locale. // The locale should use UTF-8 encoding for these tests to run successfully. - try - { + try { std::locale::global(std::locale("")); - } - catch (std::exception &) - { + } catch (std::exception &) { std::setlocale(LC_ALL, ""); } - try - { + try { + vmime::messageParser mp("<...MIME message content...>"); // Enumerate text parts - for (size_t i = 0 ; i < mp.getTextPartCount() ; ++i) - { + for (size_t i = 0 ; i < mp.getTextPartCount() ; ++i) { + const vmime::textPart& part = *mp.getTextPartAt(i); // Output content-type of the part std::cout << part.getType().generate() << std::endl; // text/html - if (part.getType().getSubType() == 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.getText()" // Corresponding plain text is in "hp.getPlainText()" // Enumerate embedded objects (eg. images) - for (size_t j = 0 ; j < hp.getObjectCount() ; ++j) - { + for (size_t j = 0 ; j < hp.getObjectCount() ; ++j) { + 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 - else - { + } else { + const vmime::textPart& tp = dynamic_cast<const vmime::textPart&>(part); // Text is in "tp.getText()" } } - } + // VMime exception - catch (vmime::exception& e) - { + } catch (vmime::exception& e) { + std::cout << "vmime::exception: " << e.what() << std::endl; throw; - } + // Standard exception - catch (std::exception& e) - { + } catch (std::exception& e) { + std::cout << "std::exception: " << e.what() << std::endl; throw; } std::cout << std::endl; + + return 0; } |