message._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * $Id: message.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
18  */
19 inherit "/kernel/module";
20 #include <macros.h>
21 #include <database.h>
22 #include <attributes.h>
23 #include <classes.h>
24 #include <exception.h>
25 //! This module converts a normal sTeam document to a Mime Object.
26 //! The object of type MimeMessage is then returned when calling
27 //! the function fetch_message(). This is used by POP3.
28 class message : public module{
29 public:
30 
31 
32 
33 
34 
35 #define HEADER_SEP "\r\n"
36 
37 
38  string sServer;
39  mapping mMessages;
40 
41 
42 string header(object obj)
43 {
44  if ( !objectp(obj) ) return "";
45  object creator = obj->get_creator();
46  string name = creator->query_attribute(USER_EMAIL);
47  if ( !stringp(name) || name == "" )
48  name = creator->get_identfier() + "@"+sServer;
49  else
50  name = creator->query_attribute(USER_FULLNAME) + " <"+name+">";
51  return "From: " + name + HEADER_SEP +
52  "Date: " + timelib.smtp_time(obj->query_attribute(OBJ_CREATION_TIME))+
53  HEADER_SEP+
54  "Subject: "+obj->query_attribute(OBJ_NAME)+HEADER_SEP+
55  "Message-ID: <" + sprintf("%010d",obj->get_object_id())+"@"+sServer+">"+HEADER_SEP+
56  "Lines: " + (sizeof((obj->get_content()/"\n"))) + HEADER_SEP;
57 }
58 
59 object fetch_message(object obj)
60 {
61  string mimetype = obj->query_attribute(DOC_MIME_TYPE);
62 #if 0
63  if ( mimetype == "text/html" || mimetype == "text/plain" ) {
64  return header(obj) + "\r\n" + obj->get_content();
65  }
66 #endif
67  object creator = obj->get_creator();
68  MIME.Message msg = MIME.Message(
69  obj->get_content(),
70  ([ "MIME-Version": "1.0",
71  "Content-Type": mimetype,
72  "Content-Transfer-Encoding": "base64",
73  "Subject": obj->get_identifier(),
74  "Message-ID": "<"+sprintf("%010d",obj->get_object_id())+"@"+sServer+">",
75  "Date": timelib.smtp_time(obj->query_attribute(OBJ_CREATION_TIME)),
76  "From": creator->get_identifier() + "@"+sServer + "("+
77  creator->query_attribute(USER_FULLNAME) + ")",
78  ]) );
79  return msg;
80 }
81 
82 /**
83  * Callback function for module initialization.
84  *
85  */
86 private:
87 void init_module()
88 {
89  sServer = _Server->get_server_name();
90  set_attribute(OBJ_DESC, "The Module converts sTeam Objects into "+
91  "mime-messages.");
92 }
93 
94 public:
95 
96 
97 string get_identifier() { return "message"; }
98 
99 
100 
101 
102 
103 
104 
105 };