summaryrefslogtreecommitdiff
path: root/htc/dml.htc
blob: 978195264c456d89b1c4379ea7f93373bd09bbbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
\include{system.htc}
\include{html.htc}
\const{dml.address}{nobody}
\def{dml.init}{xxxx}{
  %{listname}{group}{path}{http}
  \global{dml.listname}{\1}
  \global{dml.group}{\2}
  \global{dml.path}{\3}
  \global{dml.http}{\4}
  \if(count \dml.group){\open{DML}{\dml.path/data/dml.hdb}{1}}
}
\def{dml.mailuser}{xx}{
  \if{\user.id}{
    \log{mail user: \1}
    \mail{\dml.address}{}{\user.email}{DML Server}{\now}{\1}{text/plain}{\2}
  }
}
\def{dml.dfs}{xr}{
  \find.rec{\1}{
    \2;
    \query(PARENT==\1){
      \dml.dfs(INDEX){\2}
    }
  }
}
\def{dml.bfs}{xr}{
  [cur:="";bfs:=\1];
  \while(count bfs){
    [cur=first bfs];
    \find.rec(cur){\2};
    \query(PARENT==cur)(bfs=bfs+++INDEX);
    [bfs=rest bfs];
  }
}
\def{dml.ups}{xr}{
  [cur:=\1];
  \while(cur){
    \find.rec(cur){\2;[cur=PARENT]}(cur=0)
  }
}
\def{dml.watchers}{}{
  \if(count \dml.group){
    [
      m.<-@;
      break:=\dml.ups(m.INDEX){[BREAK] };
      attime:=\if(m.PROTECT)(m.TIME){\now};
      people:=\db{USERS}{\query(\allowed{\dml.group}(attime)){[UID] }}
    ];
    [people---break];
  }
}
\def{dml.resubj}{x}{
  [tmp:=first \1];\if(tmp nen "re" && tmp nen "re:"){Re: \1}{\1}
}
\def{dml.opennode}{x}{
  \db{DML}{
    \dml.ups{\1}(BREAK=BREAK---\user.id);
    \dml.confirm{Opening \dml.listname\[\1\]};
  }
}
\def{dml.closenode}{x}{
  \db{DML}{
    \find.rec{\1}{
      [BREAK=BREAK|||\user.id];
      \dml.confirm{Closing \dml.listname\[\1\]};
    }
  }
}
\def{dml.addnode}{x}{
  %(node)    - add to this node
  %T.from    - mail address
  %T.reply   - reply address
  %T.name    - user name
  %T.subject - subject
  %T.mime    - MIME type
  %T.body    - message
  %T.parts   - attachments
  %T.mime[i] - attachment MIME type
  %T.body[i] - attachment body
  %RETURN    - node number
  \db{DML}{
    [
      t.TIME:=\now;
      t.PARENT:=\1;
      t.AUTHOR:=\user.id;
      t.MIME:=\T.mime;
      t.SUBJECT:=\T.subject;
      t.BODY:=\T.body;
      t.INDEX:=\lastkey+1;
      t.PROTECT:=1;
      @<-t.;
    ];
    \log{dml: adding \dml.listname\[[INDEX]\]};
    [t.INDEX];
    \for(i:=0)(i<\T.parts)(i+=1){
      [file:="A"++INDEX++"_"++\filesafe{\T.body[i]}];
      \log{dml: uploading \dml.listname\[[file]\]};
      \save{\dml.path/attach/[file]}{T.body[i]}{385};
      [ATTACH=ATTACH|||file];
    }
  }
}
\def{dml.footer}{x}{
  \if(\1 eq "text/html"){<hr>}{----------------------------------------------}
  Help: send email to \dml.address with subject 'help \dml.listname'
}
\def{dml.quickguide}{}{
  QUICK GUIDE

  Mailing-lists on this server (\dml.address):

  \getlists;[ex:=\dml.listname]

  Mails received from the server ALWAYS starts with the listname
  enclosed in stars (*). For example,

  *[ex]\[7\]* hello world

  means you've received a message from the list '[ex]' with
  subject 'hello world'. The message is identified by its
  message number, in this case 7.

  EXAMPLES

  To post a new message on '[ex]' with subject 'hello world',
  mail to \dml.address with subject

  new [ex] hello world

  To post a new message on a particular message number, e.g. 7,
  mail to \dml.address with subject

  new [ex]\[7\] hello world

  Note that message number 1 is the message root, and is the same
  as issuing new without the \[\].

  To reply to a message from the list, use 'reply' in your mailing program,
  but DO NOT REMOVE anything before the subject. The server will
  insert the appropriate 'Re:'. For instance, replying to the first example
  above would normally give a reply-subject in your mailprogram like

  Re: *[ex]\[7\]* hello world

  which will be sent from the server as

  *[ex]\[n\]* Re: hello world

  where n is some new number assigned to your message.
}
\def{dml.message}{}{
  HELP ON USAGE OF THE *\dml.listname* MAILING LIST AT \dml.address.

  The address handles multiple mailinglists, and takes commands on the form:
  
  <cmd> <list>\[<node>\] <subject>
  or
  <cmd> *<list>\[<node>\]* <subject>
  
  where <cmd> is a command, <list> is a mailinglist,
  <node> is a message number, and <subject> is the subject
  line. The brackets \[\] should however be there as is.

  Mailing-lists on this server (\dml.address):

  \getlists
  
  You are \user.name, and your user name at \dml.address
  is \user.email. You may have clearance to several of
  the lists above.
  \if(\dml.listname eq "demo"){
    \n;
    This is a demo mailing list and will not work to send mails to.
    You will need to know the name of a list to which you belong.
  }
  Commands are not case sensitive. Available commands <cmd> are:
  
  HELP \dml.listname
  
  Displays this message.
  
  WHO \dml.listname\[<node>\]
  
  Retrieve which people are registered at the list.
  If a node number is given, it tells which people
  will receive a new message from that node.
  Note that this command may be restricted on some lists.
  
  SILENT \dml.listname\[<node>\]
  
  Adds a new message to message number <node> on \dml.listname,
  without broadcasting.
  
  NEW \dml.listname\[<node>\] <subject>
  
  Adds a new message to message number <node> on \dml.listname,
  and broadcasts to \dml.listname.
  
  REPLY \dml.listname\[<node>\] <subject>
  
  Replies to message number <node> on \dml.listname.
  Possible acronyms are Re, Re:, Sv, Sv:.
  Note that this command is issued when you do
  a normal reply, whether it be on a swedish or
  american mail program.
  
  OPEN \dml.listname\[<node>\]
  
  Opens a <node>. When a <node> is open, you recieve
  broadcast messages descending from that <node>.
  
  CLOSE \dml.listname\[<node>\]
  
  Closes a <node>. When a <node> is closed, you do not
  recieve the broadcast messages descending from that <node>.
  The obvious usage of this command is to turn off
  uninteresting of lengthy threads. Also, since everything
  added to this node will pass unnoticed, it may be used
  to structure e.q. news in topics, together with the
  SILENT command.
  
  MAIL \dml.listname\[<node>\]
  
  Retrieve message number <node> from \dml.listname.
  This command may not serve certain messages on the basis of your
  clearance and when you first entered the list.
  
  \if(\dml.listname ne "demo"){
    To get additional help on how to use this system, how to
    view or protect message trees, you may visit the
    \dml.http/ web page. Of course the commands listed
    above can be issued from there as well. You PIN code
    at the server is \user.pin.
  }
}
\def{dml.layout}{?xx}{
  [mime:=\on.arg{0}{\0}(MIME)];
  \2
  \if(ATTACH ne ""){
    \if(mime eq "text/html"){
      <hr>
      Attachments (PIN: \su{\1}{\user.pin})
      \forall{i}(ATTACH){
        \href{\dml.http/attach/[i]?alias=\su{\1}{\user.alias}}(i)\n;
      }
    }{
      ----------------------------------------------
      Attachments (PIN: \su{\1}{\user.pin})
      \forall{i}(ATTACH){
        \dml.http/attach/[i]?alias=\su{\1}{\user.alias}\n;
      }
    }
  };
  \dml.footer(mime)
}
\def{dml.error}{x}{
  %T.cmd
  %T.list
  %T.node
  %T.subject
  \mail.root{mailer: \1}{
    check <\T.cmd> \T.list\[\T.node\] \T.subject
  };
  \dml.mailuser{error}{
    An error occurred while processing your command

    \T.cmd \T.list\[\T.node\] \T.subject

    \1
    ----------------------------------------------
    \dml.quickguide
    \dml.footer(MIME)
  }
}
\def{dml.help}{}{
  \dml.mailuser{help \dml.listname}{
    \dml.quickguide

    ----------------------------------------------
    \dml.message
  }
}
\def{dml.who}{x}{
  %(node) - mail this node to group
  \db{DML}{
    \find.rec{\1}{
      \dml.mailuser{who \dml.listname}{
        PEOPLE LISTENING TO \dml.listname;\[\1\] at \dml.address

        \forall{i}{\dml.watchers}{
          \su(i){\user.name <\user.email>}\n
        }
      }
    }{
      \dml.error{Could not find node \dml.listname;\[\1\]}
    }
  }
}
\def{dml.confirm}{x}{
  %T.cmd
  %T.list
  %T.node
  %T.subject
  \dml.mailuser{\dml.listname: confirmation}{
    Your command

    \1

    was processed sucessfully.
  }
}
\def{dml.mail}{x}{
  %(node) - mail this node to user
  \db{DML}{
    \find.rec{\1}{
      [attime:=\if(PROTECT)(TIME){\now}];
      \if{\user.allow{\dml.group}(attime)}{
        \log{dml: mailing \dml.listname\[[INDEX]\] to (\user.id)};
        \mail{\su(AUTHOR){\user.email}}{}{\user.email}{\su(AUTHOR){\user.name}}
        (TIME){*\dml.listname\[[INDEX]\]* [SUBJECT]}(MIME){\dml.layout{\user.id}(BODY)};
      }{
        \log{dml: denying \dml.listname\[[INDEX]\] to (\user.id)};
        \dml.mailuser{\dml.listname\[[INDEX]\]: not found}{
          The node you requested could not be found

          (or may be protected)
        }
      }
    }{
      \dml.error{Could not find node \dml.listname;\[\1\]}
    }
  }
}
\def{dml.broadcast}{x}{
  %(node) - mail this node to group
  \db{DML}{
    \find.rec{\1}{
      \if(!BROADCAST){
        \log{dml: broadcasting \dml.listname\[[INDEX]\]}
        [
          femail:=\su(AUTHOR){\user.email};
          fname:=\su(AUTHOR){\user.name};
          fsubj:="*"++\dml.listname++"["++INDEX++"]* "++SUBJECT;
          watchers:=\dml.watchers;
          BROADCAST=count watchers;
        ];
        \forall{i}(watchers){
          [
            temail:=\su(i){\user.email};
            talias:=\su(i){\user.alias};
            tname:=\su(i){\user.name};
            tpin:=\su(i){\user.pin};
            tbody:=\replace(BODY){\recipient.email}(temail);
            tbody=\replace(tbody){\recipient.alias}(talias);
            tbody=\replace(tbody){\recipient.name}(tname);
            tbody=\replace(tbody){\recipient.pin}(tpin);
            tbody=\replace(tbody){\recipient.id}(i);
          ];
          \mail(femail){\dml.listname <\dml.address>}(temail)(fname)
          (TIME)(fsubj)(MIME){\dml.layout(i)(tbody)};
          \sleep(2);
        }
      }
    }
  }
}
\def{dml.addbroad}{x}{
  [node:=\dml.addnode{\1}];
  \if(node){
    \dml.broadcast(node)
  }{
    \dml.error{Could not add to \dml.listname;\[\1\]}
  }
}
\def{dml.addsilent}{x}{
  [node:=\dml.addnode{\1}];
  \if(node){
    \dml.confirm{Added \dml.listname\[[node]\] to \dml.listname\[\1\]}
  }{
    \dml.error{Could not add to \dml.listname;\[\1\]}
  }
}