Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

msg.ssjs 3.97 KB
Newer Older
runemaster's avatar
runemaster committed
1 2
/* $Id$ */

3 4 5 6
load("../web/lib/msgslib.ssjs");
load("../web/lib/mime_decode.ssjs");

if(msgbase.open!=undefined && msgbase.open()==false) {
7
    error(msgbase.last_error);
8 9 10 11 12
}

template.can_delete=can_delete(m);

if(sub=='mail') {
13 14
    template.group=new Object;
    template.group.name="E-Mail";
15 16
}
else {
17
    template.group=msg_area.grp[msg_area.sub[sub].grp_name];
18 19 20
}

if(sub=='mail') {
21 22 23
    template.sub=new Object;
    template.sub.description="Personal E-Mail";
    template.sub.code="mail";
24 25
}
else {
26 27 28
    template.sub=msg_area.sub[sub];
    if(!msg_area.sub[sub].can_read)
        error("You can't read messages in this sub!");
29 30 31
}

if(sub=='mail')
32
    template.can_post=!(user.security.restrictions&UFLAG_E);
33
else
34
    template.can_post=msg_area.sub[sub].can_post;
35 36 37

template.idx=msgbase.get_msg_index(false,m);
if(sub=='mail' && template.idx.to!=user.number)
38
    error("You can only read e-mail messages addressed to yourself!");
39 40
template.hdr=msgbase.get_msg_header(false,m);
if(idx_to_user(template.idx)) {
41 42 43 44
    template.hdr.attr|=MSG_READ;
    if(template.hdr.attr&MSG_KILLREAD)
        template.hdr.attr|=MSG_DELETE;
    msgbase.put_msg_header(false,m,template.hdr);
45 46 47 48 49 50 51
}
template.hdr=clean_msg_headers(template.hdr,0);
template.body=msgbase.get_msg_body(false,m);

msg=mime_decode(template.hdr,template.body);
template.body=msg.body;
if(msg.type=="plain") {
52 53 54 55 56 57 58 59 60
    /* ANSI */
    if(template.body.indexOf('\x1b[')>=0 || template.body.indexOf('\x01')>=0) {
        template.body=html_encode(template.body,true,false,true,true);
    }
    /* Plain text */
    else {
        template.body=word_wrap(template.body,80);
        template.body=html_encode(template.body,true,false,false,false);
    }
61 62
}
if(msg.attachments!=undefined) {
63 64 65 66 67
    template.attachments=new Object;
    for(att in msg.attachments) {
        template.attachments[att]=new Object;
        template.attachments[att].name=msg.attachments[att];
    }
68 69 70
}

if(template.hdr != null)  {
71
    template.title="Message: "+template.hdr.subject;
72

73 74 75 76 77 78 79 80 81 82 83 84 85
    if(sub=='mail' || user.security.level>=90) {    /* Sysops can dump all message headers */
        template.hfields="<html><head><title>Message Header Fields</title></head>";
        template.hfields+="<body>";
        template.hfields+="<h2>Message Header Fields</h2>";
        template.hfields+="<table>";
        var f;
        for(f in template.hdr)
            if(typeof(template.hdr[f])!="object")
                template.hfields+=('<tr valign=top><td>'+ f + ':<td>' + template.hdr[f]);
        for(f in template.hdr.field_list)
            template.hfields+=('<tr valign=top><td>type-0x'
                + format("%02X",template.hdr.field_list[f].type) + ':<td>'
                + strip_ctrl(template.hdr.field_list[f].data));
86

87 88 89 90
        template.hfields+="</table>";
        template.hfields+="</body>";
        template.hfields+="</html>";
    }
91 92 93
}

var tmp=find_np_message(template.idx.offset,true);
94
template.temp=tmp
95 96
template.replyto=undefined;
if(template.hdr.thread_orig!=0) {
97 98 99
    template.replyto=msgbase.get_msg_header(false,template.hdr.thread_orig);
    if(template.replyto==null)
        template.replyto=undefined;
100 101 102
}
template.replies=new Array;
if(template.hdr.thread_first!=0) {
103 104 105 106 107 108 109 110 111
    /* Fill replies array */
    var next_reply;
    var rhdr=new Object;
    rhdr.thread_next=template.hdr.thread_first;
    for(;(next_reply=rhdr.thread_next)!=0 && (rhdr=msgbase.get_msg_header(false,next_reply))!=null;) {
        if(rhdr==null)
            break;
        template.replies.push(rhdr);
    }
112 113
}
if(tmp!=undefined)
114
    template.prevlink='<a href="msg.ssjs?msg_sub='+sub+'&amp;message='+tmp+'">'+prev_msg_html+'</a>';
115
else
116
    template.prevlink=no_prev_msg_html;
117 118
tmp=find_np_message(template.idx.offset,false);
if(tmp!=undefined)
119
    template.nextlink='<a href="msg.ssjs?msg_sub='+sub+'&amp;message='+tmp+'">'+next_msg_html+'</a>';
120
else
121
    template.nextlink=no_next_msg_html;
122 123

write_template("header.inc");
124
load("../web/lib/topnav_html.ssjs");
runemaster's avatar
runemaster committed
125
load("../web/lib/leftnav_html.ssjs");
126 127 128 129
write_template("msgs/msg.inc");
write_template("footer.inc");

msgs_done();