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 6.53 KB
Newer Older
runemaster's avatar
runemaster committed
1 2
/* $Id$ */

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

6
template.txtbodybgwht=0;
runemaster's avatar
runemaster committed
7 8
template.author_avatar = '';

9

runemaster's avatar
runemaster committed
10 11 12 13 14
/*  If you want to disable display of certain .inc files  */
/* for a specific theme declare it like this in the .ssjs */
/* file corresponding to the page you want to overide the */
/*           default display type for the theme			  */

15
if(do_extra) {
runemaster's avatar
runemaster committed
16 17 18 19
	do_leftnav=false;
	do_rightnav=false;
}

20
if(msgbase.open!=undefined && msgbase.open()==false) {
21
    error(msgbase.last_error);
22 23
}

runemaster's avatar
runemaster committed
24 25 26
/* Check author info if message base is local and display it */
/*    on the new expanded message read page for new theme    */

27
var hdr=msgbase.get_msg_header(false,m);
28 29
if(hdr==null)
	error(msgbase.last_error);
30 31
if(hdr.attr&MSG_DELETE)
	error("Deleted message");
32 33 34 35 36 37 38 39
if((!(system.settings & SYS_USRVDELM)) || (user.security.level >= 90 && (!(system.settings & SYS_SYSVDELM))) ) {
	if(hdr.attr & MSG_DELETE)
		error("Message has been deleted");
}
if(hdr.attr & MSG_MODERATED) {
	if(!(hdr.attr & MSG_VALIDATED))
		error("Message pending moderator validation");
}
40
if(Number(hdr.from_ext) > 0) {
runemaster's avatar
runemaster committed
41 42 43 44
	template.u_num = hdr.from_ext;
	usr = new User(template.u_num);
	template.author_firston = strftime("%m/%d/%y",usr.stats.firston_date);
	template.author_posts = usr.stats.total_posts;
45
	if(sub!='mail') {
runemaster's avatar
runemaster committed
46 47 48 49 50 51 52 53 54 55 56 57 58
	if((user.compare_ars(msg_area.sub[sub].operator_ars) && msg_area.sub[sub].operator_ars != '' || user.number==1) && show_ip==true) {
		template.author_ip='IP: ' + usr.note + '<br /><br />';
	}
	template.author_ismod = '<br />Member<br /><br />';
	if(usr.compare_ars(msg_area.sub[sub].operator_ars) && msg_area.sub[sub].operator_ars != '' || usr.number==1)
		template.author_ismod = '<br />Moderator<br /><br />';
	if(file_exists(prefs_dir + format("%04d.html_prefs",usr.number))); {
		prefsfile=new File(prefs_dir + format("%04d.html_prefs",usr.number));
		if(prefsfile.open("r",false)) {
			if(prefsfile.iniGetValue('Profile', 'Avatar', '')!='') {
				template.author_avatar=prefsfile.iniGetValue('Profile', 'Avatar', '');
				var display_info=true;
			} else
59 60 61
				template.author_avatar = template.image_dir + "/nothumbnail.jpg";
				prefsfile.close();
			}
runemaster's avatar
runemaster committed
62 63 64 65
		}
	}
}

66 67 68
template.can_delete=can_delete(m);

if(sub=='mail') {
69 70
    template.group=new Object;
    template.group.name="E-Mail";
runemaster's avatar
runemaster committed
71
} else {
72
    template.group=msg_area.grp[msg_area.sub[sub].grp_name];
73 74 75
}

if(sub=='mail') {
76 77 78
    template.sub=new Object;
    template.sub.description="Personal E-Mail";
    template.sub.code="mail";
79 80
}
else {
81 82 83
    template.sub=msg_area.sub[sub];
    if(!msg_area.sub[sub].can_read)
        error("You can't read messages in this sub!");
84 85 86
}

if(sub=='mail')
87
    template.can_post=!(user.security.restrictions&UFLAG_E);
88
else
89
    template.can_post=msg_area.sub[sub].can_post;
90

91 92 93 94 95
max_display=Themes[CurrTheme].msgs_displayed + m;
start_num = m;

// for(i = start_num; i <= max_display ; i++) {

96 97
template.idx=msgbase.get_msg_index(false,m);
if(sub=='mail' && template.idx.to!=user.number)
98
    error("You can only read e-mail messages addressed to yourself!");
99
template.hdr=msgbase.get_msg_header(false,m, /* expand_fields: */false);
100
if(idx_to_user(template.idx)) {
101 102 103 104
    template.hdr.attr|=MSG_READ;
    if(template.hdr.attr&MSG_KILLREAD)
        template.hdr.attr|=MSG_DELETE;
    msgbase.put_msg_header(false,m,template.hdr);
105 106
}
template.hdr=clean_msg_headers(template.hdr,0);
107
template.body=msgbase.get_msg_body(false,m,template.hdr);
108 109 110 111

msg=mime_decode(template.hdr,template.body);
template.body=msg.body;
if(msg.type=="plain") {
112 113
    /* ANSI */
    if(template.body.indexOf('\x1b[')>=0 || template.body.indexOf('\x01')>=0) {
114
        template.body=html_encode(template.body, !template.hdr.is_utf8, false,true,true);
115
		template.body=make_links(template.body);
116 117 118
    }
    /* Plain text */
    else {
119
        template.body=word_wrap(template.body,80);
120
        template.body=html_encode(template.body, !template.hdr.is_utf8, false,false,false);
121
		template.body=make_links(template.body);
122
    }
123
}
124

125
if(msg.attachments!=undefined) {
126 127 128 129 130
    template.attachments=new Object;
    for(att in msg.attachments) {
        template.attachments[att]=new Object;
        template.attachments[att].name=msg.attachments[att];
    }
131 132 133
}

if(template.hdr != null)  {
134
    if(Themes[CurrTheme].do_forumlook==true && sub!='mail')
135
		template.title="Reading Messages in "+template.group.description + " -> " + template.sub.description;
136
	else
137 138
		template.title="Message: "+template.hdr.subject;
	
139 140 141 142 143 144 145 146 147 148 149 150 151
    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));
152

153 154 155 156
        template.hfields+="</table>";
        template.hfields+="</body>";
        template.hfields+="</html>";
    }
157 158
}

159 160 161
if(msg.type!="plain" && sub=="mail")
  template.txtbodybgwht=1;

162
var tmp=find_np_message(template.idx.offset,true);
163
template.temp=tmp
164 165
template.replyto=undefined;
if(template.hdr.thread_orig!=0) {
166 167 168
    template.replyto=msgbase.get_msg_header(false,template.hdr.thread_orig);
    if(template.replyto==null)
        template.replyto=undefined;
169 170 171
}
template.replies=new Array;
if(template.hdr.thread_first!=0) {
172 173 174 175 176 177 178 179 180
    /* 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);
    }
181
}
182 183


184
if(tmp!=undefined)
185
    template.prevlink='<a href="msg.ssjs?msg_sub='+sub+'&amp;message='+tmp+'">'+prev_msg_html+'</a>';
186
else
187
    template.prevlink=no_prev_msg_html;
188 189
tmp=find_np_message(template.idx.offset,false);
if(tmp!=undefined)
190
    template.nextlink='<a href="msg.ssjs?msg_sub='+sub+'&amp;message='+tmp+'">'+next_msg_html+'</a>';
191
else
192
    template.nextlink=no_next_msg_html;
193

194 195
// m--;

196 197 198 199 200 201 202 203
if(do_header)
	write_template("header.inc");
if(do_topnav)
	load(topnav_html);
if(do_leftnav)
	load(leftnav_html);
if(do_rightnav)
	write_template("rightnav.inc");
204
write_template("msgs/msg.inc");
205 206 207

// }

runemaster's avatar
runemaster committed
208 209
if(do_footer)
	write_template("footer.inc");
210 211

msgs_done();