~ubuntu-branches/ubuntu/wily/cxxtools/wily-proposed

« back to all changes in this revision

Viewing changes to demo/mime.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kari Pahula
  • Date: 2008-06-16 12:24:28 UTC
  • mfrom: (3.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616122428-7bllgyt1358u779r
Tags: 1.4.8-2
Made libcxxtools-dev depend on libcxxtools6, not libcxxtools5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2007 Tommi Maekitalo
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; either version 2 of the
 
7
 * License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful, but
 
10
 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
 
11
 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
 
12
 * NON-INFRINGEMENT.  See the GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
17
 *
 
18
 */
 
19
 
 
20
#include <iostream>
 
21
#include <fstream>
 
22
#include <stdexcept>
 
23
#include <cxxtools/mime.h>
 
24
#include <cxxtools/loginit.h>
 
25
 
 
26
int main(int argc, char* argv[])
 
27
{
 
28
  try
 
29
  {
 
30
    log_init();
 
31
 
 
32
    cxxtools::Mime mime;
 
33
 
 
34
    for (int a = 1; a < argc; ++a)
 
35
    {
 
36
      std::string fname = argv[a];
 
37
 
 
38
      std::ifstream ifile(argv[a]);
 
39
      if (!ifile)
 
40
        throw std::runtime_error("cannot open file " + fname);
 
41
 
 
42
      if (fname.size() >= 4 && fname.compare(fname.size() - 4, 4, ".jpg") == 0)
 
43
        mime.addBinaryFile("image/jpg", fname, ifile);
 
44
      else if (fname.size() >= 4 && fname.compare(fname.size() - 4, 4, ".gif") == 0)
 
45
        mime.addBinaryFile("image/gif", fname, ifile);
 
46
      else if (fname.size() >= 4 && fname.compare(fname.size() - 4, 4, ".png") == 0)
 
47
        mime.addBinaryFile("image/png", fname, ifile);
 
48
      else
 
49
        mime.addPart(ifile);
 
50
    }
 
51
 
 
52
    std::cout << mime;
 
53
  }
 
54
  catch (const std::exception& e)
 
55
  {
 
56
    std::cerr << e.what() << std::endl;
 
57
  }
 
58
}
 
59