msg.ssjs 6.68 KB
Newer Older
1
/* $Id: msg.ssjs,v 1.55 2019/07/24 09:30:23 rswindell Exp $ */
runemaster's avatar
runemaster committed
2

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 21
if(!msgbase)
    error("msgbase not defined");
22
if(msgbase.open!=undefined && msgbase.open()==false) {
23
    error(msgbase.last_error);
24 25
}

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

29
var hdr=msgbase.get_msg_header(false,m);
30 31
if(hdr==null)
	error(msgbase.last_error);
32 33
if(hdr.attr&MSG_DELETE)
	error("Deleted message");
34 35 36 37 38 39 40 41
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");
}
42
if(Number(hdr.from_ext) > 0) {
runemaster's avatar
runemaster committed
43
	template.u_num = hdr.from_ext;
44 45 46 47 48 49 50
	usr = null;
	try {
		usr = new User(template.u_num);
		template.author_firston = strftime("%m/%d/%y",usr.stats.firston_date);
		template.author_posts = usr.stats.total_posts;
	} catch(e) {
	}
51
	if(sub!='mail') {
runemaster's avatar
runemaster committed
52 53 54 55
	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 />';
56
	if(usr && (usr.compare_ars(msg_area.sub[sub].operator_ars) && msg_area.sub[sub].operator_ars != '' || usr.number==1))
runemaster's avatar
runemaster committed
57
		template.author_ismod = '<br />Moderator<br /><br />';
58
	if(usr && file_exists(prefs_dir + format("%04d.html_prefs",usr.number))) {
runemaster's avatar
runemaster committed
59 60 61 62 63 64
		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
65 66 67
				template.author_avatar = template.image_dir + "/nothumbnail.jpg";
				prefsfile.close();
			}
runemaster's avatar
runemaster committed
68 69 70 71
		}
	}
}

72 73 74
template.can_delete=can_delete(m);

if(sub=='mail') {
75 76
    template.group=new Object;
    template.group.name="E-Mail";
runemaster's avatar
runemaster committed
77
} else {
78
    template.group=msg_area.grp[msg_area.sub[sub].grp_name];
79 80 81
}

if(sub=='mail') {
82 83 84
    template.sub=new Object;
    template.sub.description="Personal E-Mail";
    template.sub.code="mail";
85 86
}
else {
87 88 89
    template.sub=msg_area.sub[sub];
    if(!msg_area.sub[sub].can_read)
        error("You can't read messages in this sub!");
90 91 92
}

if(sub=='mail')
93
    template.can_post=!(user.security.restrictions&UFLAG_E);
94
else
95
    template.can_post=msg_area.sub[sub].can_post;
96

97 98 99 100 101
max_display=Themes[CurrTheme].msgs_displayed + m;
start_num = m;

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

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

msg=mime_decode(template.hdr,template.body);
template.body=msg.body;
if(msg.type=="plain") {
118 119
    /* ANSI */
    if(template.body.indexOf('\x1b[')>=0 || template.body.indexOf('\x01')>=0) {
120
        template.body=html_encode(template.body, !template.hdr.is_utf8, false,true,true);
121
		template.body=make_links(template.body);
122 123 124
    }
    /* Plain text */
    else {
125
        template.body=word_wrap(template.body,80);
126
        template.body=html_encode(template.body, !template.hdr.is_utf8, false,false,false);
127
		template.body=make_links(template.body);
128
    }
129
}
130

131
if(msg.attachments!=undefined) {
132 133 134 135 136
    template.attachments=new Object;
    for(att in msg.attachments) {
        template.attachments[att]=new Object;
        template.attachments[att].name=msg.attachments[att];
    }
137 138 139
}

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

159 160 161 162
        template.hfields+="</table>";
        template.hfields+="</body>";
        template.hfields+="</html>";
    }
163 164
}

165 166 167
if(msg.type!="plain" && sub=="mail")
  template.txtbodybgwht=1;

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


190
if(tmp!=undefined)
191
    template.prevlink='<a href="msg.ssjs?msg_sub='+sub+'&amp;message='+tmp+'">'+prev_msg_html+'</a>';
192
else
193
    template.prevlink=no_prev_msg_html;
194 195
tmp=find_np_message(template.idx.offset,false);
if(tmp!=undefined)
196
    template.nextlink='<a href="msg.ssjs?msg_sub='+sub+'&amp;message='+tmp+'">'+next_msg_html+'</a>';
197
else
198
    template.nextlink=no_next_msg_html;
199

200 201
// m--;

202 203 204 205 206 207 208 209
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");
210
write_template("msgs/msg.inc");
211 212 213

// }

runemaster's avatar
runemaster committed
214 215
if(do_footer)
	write_template("footer.inc");
216 217

msgs_done();