~ubuntu-branches/ubuntu/edgy/lurker/edgy

« back to all changes in this revision

Viewing changes to render/mbox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Meurer
  • Date: 2004-09-26 16:27:51 UTC
  • Revision ID: james.westby@ubuntu.com-20040926162751-z1ohcjltv7ojtg6z
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: mbox.cpp,v 1.9 2004/08/24 16:16:35 terpstra Exp $
 
2
 *  
 
3
 *  mbox.cpp - Handle a mbox/ command
 
4
 *  
 
5
 *  Copyright (C) 2002 - Wesley W. Terpstra
 
6
 *  
 
7
 *  License: GPL
 
8
 *  
 
9
 *  Authors: 'Wesley W. Terpstra' <wesley@terpstra.ca>
 
10
 *  
 
11
 *    This program is free software; you can redistribute it and/or modify
 
12
 *    it under the terms of the GNU General Public License as published by
 
13
 *    the Free Software Foundation; version 2.
 
14
 *    
 
15
 *    This program is distributed in the hope that it will be useful,
 
16
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *    GNU General Public License for more details.
 
19
 *    
 
20
 *    You should have received a copy of the GNU General Public License
 
21
 *    along with this program; if not, write to the Free Software
 
22
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 */
 
24
 
 
25
#define _XOPEN_SOURCE 500
 
26
#define _FILE_OFFSET_BITS 64
 
27
 
 
28
#include <mimelib/message.h>
 
29
 
 
30
#include "commands.h"
 
31
#include "Summary.h"
 
32
#include "Cache.h"
 
33
 
 
34
int handle_mbox(const Config& cfg, ESort::Reader* db, const string& param)
 
35
{
 
36
        Request req = parse_request(param);
 
37
        
 
38
        if (!MessageId::is_full(req.options.c_str()))
 
39
        {
 
40
                cout << "Status: 200 OK\r\n";
 
41
                cout << "Content-Type: text/html\r\n\r\n";
 
42
                cout << error(_("Bad request"), param,
 
43
                        _("The given parameter was not of the correct format. "
 
44
                          "A mbox request must be formatted like: "
 
45
                          "mbox/YYYYMMDD.HHMMSS.hashcode.txt"));
 
46
                return 1;
 
47
        }
 
48
        
 
49
        if (!cfg.raw_email)
 
50
        {
 
51
                cout << "Status: 200 OK\r\n";
 
52
                cout << "Content-Type: text/html\r\n\r\n";
 
53
                cout << error(_("Permission Denied"), param,
 
54
                        _("Access to raw email text has been disabled. "
 
55
                          "Contact the site administrator if this is a problem."));
 
56
                return 1;
 
57
        }
 
58
        
 
59
        MessageId id(req.options.c_str());
 
60
        string ok;
 
61
        
 
62
        Summary source(id);
 
63
        if ((ok = source.load(db, cfg)) != "")
 
64
        {
 
65
                cout << "Status: 200 OK\r\n";
 
66
                cout << "Content-Type: text/html\r\n\r\n";
 
67
                cout << error(_("Database mbox source pull failure"), ok,
 
68
                        _("The specified message does not exist."));
 
69
                return 1;
 
70
        }
 
71
        
 
72
        DwMessage message;
 
73
        if ((ok = source.message(cfg.dbdir, message)) != "")
 
74
        {
 
75
                cout << "Status: 200 OK\r\n";
 
76
                cout << "Content-Type: text/html\r\n\r\n";
 
77
                cout << error(_("MBox read failure"), ok,
 
78
                        _("Unable to open message in the mailbox. "
 
79
                          "Perhaps it has been deleted or moved?"));
 
80
                return 1;
 
81
        }
 
82
        
 
83
        Cache cache(cfg, "mbox", param, req.ext);
 
84
        cache.o << message.AsString().c_str();
 
85
        
 
86
        return 0;
 
87
}