1 /* Copyright (C) 2000-2004  Thomas Bopp, Thorsten Hampel, Ludger Merkens
     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.
     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.
    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
    17  * $Id: message.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
    19 inherit "/kernel/module";
    22 #include <attributes.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{
    35 #define HEADER_SEP "\r\n"
    42 string header(object obj)
    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;
    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))+
    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;
    59 object fetch_message(object obj)
    61     string mimetype = obj->query_attribute(DOC_MIME_TYPE);
    63     if ( mimetype == "text/html" || mimetype == "text/plain" ) {
    64    return header(obj) + "\r\n" + obj->get_content();
    67     object creator = obj->get_creator();
    68     MIME.Message msg = MIME.Message(
    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) + ")",
    83  * Callback function for module initialization.
    89     sServer = _Server->get_server_name();
    90     set_attribute(OBJ_DESC, "The Module converts sTeam Objects into "+
    97 string get_identifier() { return "message"; }