forked from alandipert/ncsa-mosaic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailto.c
748 lines (610 loc) · 23.3 KB
/
mailto.c
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
/****************************************************************************
* NCSA Mosaic for the X Window System *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* Copyright (C) 1993, Board of Trustees of the University of Illinois *
* *
* NCSA Mosaic software, both binary and source (hereafter, Software) is *
* copyrighted by The Board of Trustees of the University of Illinois *
* (UI), and ownership remains with the UI. *
* *
* The UI grants you (hereafter, Licensee) a license to use the Software *
* for academic, research and internal business purposes only, without a *
* fee. Licensee may distribute the binary and source code (if released) *
* to third parties provided that the copyright notice and this statement *
* appears on all copies and that no charge is associated with such *
* copies. *
* *
* Licensee may make derivative works. However, if Licensee distributes *
* any derivative work based on or derived from the Software, then *
* Licensee will (1) notify NCSA regarding its distribution of the *
* derivative work, and (2) clearly notify users that such derivative *
* work is a modified version and not the original NCSA Mosaic *
* distributed by the UI. *
* *
* Any Licensee wishing to make commercial use of the Software should *
* contact the UI, c/o NCSA, to negotiate an appropriate license for such *
* commercial use. Commercial use includes (1) integration of all or *
* part of the source code into a product for sale or license by or on *
* behalf of Licensee to third parties, or (2) distribution of the binary *
* code or source code to third parties that need it to utilize a *
* commercial product sold or licensed by or on behalf of Licensee. *
* *
* UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR *
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED *
* WARRANTY. THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE *
* USERS OF THIS SOFTWARE. *
* *
* By using or copying this Software, Licensee agrees to abide by the *
* copyright law and all other applicable laws of the U.S. including, but *
* not limited to, export control laws, and the terms of this license. *
* UI shall have the right to terminate this license immediately by *
* written notice upon Licensee's breach of, or non-compliance with, any *
* of its terms. Licensee may be held legally responsible for any *
* copyright infringement that is caused or encouraged by Licensee's *
* failure to abide by the terms of this license. *
* *
* Comments and questions are welcome and can be sent to *
* [email protected]. *
****************************************************************************/
/* Interface for mailto: URLs, stolen from techsupport.c */
#include "../config.h"
#include "mosaic.h"
#include "gui.h"
#include <stdio.h>
#include "../libnut/url-utils.h"
#include "libnut/system.h"
#ifndef DISABLE_TRACE
extern int srcTrace;
#endif
extern int do_post;
extern char *post_content_type;
extern char *post_data;
extern char pre_title[80];
extern mo_window *current_win;
mo_status mo_post_mailto_form_win (char *to_address, char *subject);
mo_status mo_send_mailto_message (char *text, char *to, char *subj,
char *content_type, char *url);
void do_mailto_post(mo_window *win, char *to, char *from, char *subject,
char *body);
/* ----------------------- mo_post_mailto_window ------------------------ */
static XmxCallback (include_fsb_cb)
{
char *fname, efname[MO_LINE_LENGTH];
FILE *fp;
char line[MO_LINE_LENGTH], *status;
mo_window *win = mo_fetch_window_by_id (XmxExtractUniqid ((int)client_data));
if (!win)
return;
XtUnmanageChild (win->mail_fsb_win);
fname = (char *)malloc (128 * sizeof (char));
XmStringGetLtoR (((XmFileSelectionBoxCallbackStruct *)call_data)->value,
XmSTRING_DEFAULT_CHARSET,
&fname);
pathEval (efname, fname);
fp = fopen (efname, "r");
if (!fp)
{
char *buf, *final, tmpbuf[80];
int final_len;
buf=my_strerror(errno);
if (!buf || !*buf || !strcmp(buf,"Error 0")) {
sprintf(tmpbuf,"Unknown Error");
buf=tmpbuf;
}
final_len=30+((!efname || !*efname?3:strlen(efname))+13)+15+(strlen(buf)+13);
final=(char *)calloc(final_len,sizeof(char));
strcpy(final,"\nUnable to Open File:\n");
sprintf(final+strlen(final)," %s\n",(!efname || !*efname?" ":efname));
sprintf(final+strlen(final),"\nOpen Error:\n");
sprintf(final+strlen(final)," %s\n",buf);
XmxMakeErrorDialog (win->mailto_win,
final,
"Open Error");
XtManageChild (Xmx_w);
if (final) {
free(final);
final=NULL;
}
return;
}
while (1)
{
long pos;
status = fgets (line, MO_LINE_LENGTH, fp);
if (!status || !(*line))
break;
XmTextInsert (win->mailto_text,
pos = XmTextGetInsertionPosition (win->mailto_text),
line);
/* move insertion position to past this line to avoid inserting the
lines in reverse order */
XmTextSetInsertionPosition (win->mailto_text, pos + strlen(line));
}
return;
}
static XmxCallback (mailto_win_cb)
{
mo_window *win = mo_fetch_window_by_id (XmxExtractUniqid ((int)client_data));
char *msg, *subj, *to;
long pos;
switch (XmxExtractToken ((int)client_data))
{
case 0: /* send */
XtUnmanageChild (win->mailto_win);
msg = XmxTextGetString (win->mailto_text);
if (!msg)
return;
if (msg[0] == '\0')
return;
to = XmxTextGetString (win->mailto_tofield);
subj = XmxTextGetString (win->mailto_subfield);
mo_send_mailto_message (msg, to, subj, "text/plain",
win->current_node->url);
free (msg);
free (to);
free (subj);
break;
case 1: /* dismiss */
XtUnmanageChild (win->mailto_win);
/* Do nothing. */
break;
case 2: /* help */
mo_open_another_window
(win,
mo_assemble_help_url ("help-on-mailto.html"),
NULL, NULL);
break;
case 3: /* insert file */
if (!win->mail_fsb_win) {
win->mail_fsb_win = XmxMakeFileSBDialog
(win->mailto_win,
"NCSA Mosaic: Include File In Mail Message",
"Name of file to include:",
include_fsb_cb, 0);
} else {
XmFileSelectionDoSearch (win->mail_fsb_win, NULL);
}
XmxManageRemanage (win->mail_fsb_win);
break;
case 4:
if(win->current_node->url){
XmTextInsert (win->mailto_text,
pos = XmTextGetInsertionPosition (win->mailto_text),
win->current_node->url);
/* move insertion position to past this line
to avoid inserting the lines in reverse order */
XmTextSetInsertionPosition (win->mailto_text,
pos + strlen(win->current_node->url));
}
break;
}
return;
}
static XmxCallback (mailto_form_win_cb)
{
mo_window *win = mo_fetch_window_by_id (XmxExtractUniqid ((int)client_data));
char *subj, *to, *namestr;
switch (XmxExtractToken ((int)client_data))
{
case 0: /* send */
XtUnmanageChild (win->mailto_form_win);
to = XmxTextGetString (win->mailto_form_tofield);
subj = XmxTextGetString (win->mailto_form_subfield);
namestr = XmxTextGetString(win->mailto_form_fromfield);
do_mailto_post(win,to,namestr,subj,win->post_data);
free (namestr);
free (to);
free (subj);
if (win->post_data) {
free (win->post_data);
win->post_data=NULL;
}
break;
case 1: /* dismiss */
XtUnmanageChild (win->mailto_form_win);
/* Do nothing. */
if (win->post_data) {
free (win->post_data);
win->post_data=NULL;
}
break;
case 2: /* help */
mo_open_another_window
(win,
mo_assemble_help_url ("help-on-mailto-form.html"),
NULL, NULL);
break;
}
return;
}
mo_status mo_post_mailto_win (char *to_address, char *subject)
{
mo_window *win = current_win;
FILE *fp;
long pos;
char namestr[1024],tmp[1024];
if (do_post) {
if (!subject || !*subject) {
char str[BUFSIZ];
sprintf(str,"Form Result(s) Posted from %s",pre_title);
return(mo_post_mailto_form_win(to_address,str));
}
else {
return(mo_post_mailto_form_win(to_address,subject));
}
}
if (!win->mailto_win)
{
Widget dialog_frame;
Widget dialog_sep, buttons_form;
Widget mailto_form;
Widget tolabel, sublabel, fromlabel;
/* Create it for the first time. */
XmxSetUniqid (win->id);
win->mailto_win = XmxMakeFormDialog
(win->base, "NCSA Mosaic: Mail To Author");
dialog_frame = XmxMakeFrame (win->mailto_win, XmxShadowOut);
/* Constraints for base. */
XmxSetConstraints
(dialog_frame, XmATTACH_FORM, XmATTACH_FORM,
XmATTACH_FORM, XmATTACH_FORM, NULL, NULL, NULL, NULL);
/* Main form. */
mailto_form = XmxMakeForm (dialog_frame);
XmxSetArg (XmNscrolledWindowMarginWidth, (XtArgVal)10);
XmxSetArg (XmNscrolledWindowMarginHeight, (XtArgVal)10);
XmxSetArg (XmNcursorPositionVisible, (XtArgVal)True);
XmxSetArg (XmNeditable, (XtArgVal)True);
XmxSetArg (XmNeditMode, (XtArgVal)XmMULTI_LINE_EDIT);
XmxSetArg (XmNrows, (XtArgVal)15);
XmxSetArg (XmNcolumns, (XtArgVal)80);
/* XmxSetArg (XmNwordWrap, (XtArgVal)True); */
/* XmxSetArg (XmNscrollHorizontal, (XtArgVal)False); */
win->mailto_text = XmxMakeScrolledText (mailto_form);
dialog_sep = XmxMakeHorizontalSeparator (mailto_form);
/* create from, to, and subject widgets */
fromlabel = XmxMakeLabel(mailto_form, "From:");
XmxSetArg (XmNeditable, (XtArgVal)False); /* for now, at least */
win->mailto_fromfield = XmxMakeTextField(mailto_form);
tolabel = XmxMakeLabel(mailto_form, "To:");
win->mailto_tofield = XmxMakeTextField(mailto_form);
sublabel = XmxMakeLabel(mailto_form, "Subject:");
win->mailto_subfield = XmxMakeTextField(mailto_form);
/* constraints for FROM */
XmxSetOffsets(fromlabel, 14, 10, 10, 10);
XmxSetConstraints
(fromlabel, XmATTACH_FORM, XmATTACH_NONE, XmATTACH_FORM,
XmATTACH_NONE, NULL, NULL, NULL, NULL);
XmxSetOffsets(win->mailto_fromfield, 10, 10, 10, 10);
XmxSetConstraints
(win->mailto_fromfield, XmATTACH_FORM, XmATTACH_NONE, XmATTACH_WIDGET,
XmATTACH_FORM, NULL, NULL, fromlabel, NULL);
/* constraints for TO */
XmxSetOffsets(tolabel, 14, 10, 10, 10);
XmxSetConstraints
(tolabel, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_NONE,
win->mailto_fromfield, NULL, NULL, NULL);
XmxSetOffsets(win->mailto_tofield, 10, 10, 10, 10);
XmxSetConstraints
(win->mailto_tofield, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_WIDGET,
XmATTACH_FORM, win->mailto_fromfield, NULL, tolabel, NULL);
/* constraints for SUBJECT */
XmxSetOffsets(sublabel, 14, 10, 10, 10);
XmxSetConstraints
(sublabel, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM,
XmATTACH_NONE, win->mailto_tofield, NULL, NULL, NULL);
XmxSetOffsets(win->mailto_subfield, 10, 10, 10, 10);
XmxSetConstraints
(win->mailto_subfield, XmATTACH_WIDGET, XmATTACH_NONE,
XmATTACH_WIDGET, XmATTACH_FORM, win->mailto_tofield, NULL,
sublabel, NULL);
/* create buttons */
buttons_form = XmxMakeFormAndFiveButtons
(mailto_form, mailto_win_cb,
"Send", "Insert File", "Insert URL", "Dismiss", "Help...",
0, 3, 4, 1, 2);
XmxSetOffsets (XtParent (win->mailto_text), 3, 0, 3, 3);
XmxSetConstraints
(XtParent (win->mailto_text), XmATTACH_WIDGET, XmATTACH_WIDGET,
XmATTACH_FORM, XmATTACH_FORM,
win->mailto_subfield, dialog_sep, NULL, NULL);
XmxSetArg (XmNtopOffset, (XtArgVal)10);
XmxSetConstraints
(dialog_sep, XmATTACH_NONE, XmATTACH_WIDGET, XmATTACH_FORM,
XmATTACH_FORM,
NULL, buttons_form, NULL, NULL);
XmxSetConstraints
(buttons_form, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_FORM,
XmATTACH_FORM, NULL, NULL, NULL, NULL);
}
/* fill in text fields */
sprintf(namestr, "%s <%s>", get_pref_string(eDEFAULT_AUTHOR_NAME),
get_pref_string(eDEFAULT_AUTHOR_EMAIL));
XmxTextSetString (win->mailto_fromfield, namestr);
XmxTextSetString (win->mailto_tofield, to_address);
if (!subject || !*subject) {
char str[BUFSIZ];
sprintf(str,"Mail from %s",pre_title);
XmTextFieldSetString(win->mailto_subfield,str);
}
else {
XmTextFieldSetString(win->mailto_subfield,subject);
}
XmxTextSetString (win->mailto_text, "");
/* tack signature on the end if it exists - code from Martin Hamilton */
if (get_pref_string(eSIGNATURE)) {
XmxTextSetString (win->mailto_text, "\n\n");
/* leave a gap... */
XmTextSetInsertionPosition (win->mailto_text, 2);
if ((fp = fopen(get_pref_string(eSIGNATURE), "r")) != NULL) {
while(fgets(tmp, sizeof(tmp) - 1, fp)) {
XmTextInsert(win->mailto_text,
pos = XmTextGetInsertionPosition (win->mailto_text),
tmp);
XmTextSetInsertionPosition (win->mailto_text, pos + strlen(tmp));
}
fclose(fp);
} else {
XmxTextSetString (win->mailto_text, "");
}
}
XmTextSetInsertionPosition (win->mailto_text, 0);
XmxManageRemanage (win->mailto_win);
return mo_succeed;
}
void eatSpace(char *s) {
char *p,*p0;
for (p=s; *s; s++) {
if (isspace(*s)) {
*s=' '; /*Get rid of anything like TAB*/
p=(++s);
while (*s && isspace(*s)) s++;
if (!*s) {
*p='\0';
return;
}
if (s>p) {
for (p0=p;*s;s++,p++) *p=(*s);
*p='\0';
s=p0;
}
}
}
return;
}
char *makeReadable(char *str, int condense) {
char *buf=NULL,*name=NULL,*val=NULL;
char *b=NULL;
b=strdup(str);
/*decode the encoded info (str) into name-value pairs*/
buf=(char *)calloc((strlen(b)*3),sizeof(char));
if (!buf) {
return(NULL);
}
sprintf(buf,"\n");
for(; (b && *b) ;) {
val = makeword(b,'&');
plustospace(val);
unescape_url(val);
name = makeword(val,'=');
if (condense) { /*take out all "multiple isspace()"*/
eatSpace(val);
}
sprintf(buf,"%sNAME=[%s]\nVALUE=[%s]\n\n",(buf && *buf?buf:"\n"),(name && *name?name:"(NULL)"),(val && *val?val:"(NULL)"));
if (val) {
free(val);
val=NULL;
}
if (name) {
free(name);
name=NULL;
}
}
free(b);
return(buf);
}
mo_status mo_post_mailto_form_win (char *to_address, char *subject)
{
mo_window *win = current_win;
FILE *fp;
long pos;
char namestr[1024],tmp[1024],*buf=NULL;
if (!do_post) {
return(mo_fail);
}
if (!win->mailto_form_win)
{
Widget dialog_frame;
Widget dialog_sep, buttons_form;
Widget mailto_form_form;
Widget tolabel, sublabel, fromlabel;
/* Create it for the first time. */
XmxSetUniqid (win->id);
win->mailto_form_win = XmxMakeFormDialog
(win->base, "NCSA Mosaic: Mail Form Results To Author");
dialog_frame = XmxMakeFrame (win->mailto_form_win, XmxShadowOut);
/* Constraints for base. */
XmxSetConstraints
(dialog_frame, XmATTACH_FORM, XmATTACH_FORM,
XmATTACH_FORM, XmATTACH_FORM, NULL, NULL, NULL, NULL);
/* Main form. */
mailto_form_form = XmxMakeForm (dialog_frame);
XmxSetArg (XmNscrolledWindowMarginWidth, (XtArgVal)10);
XmxSetArg (XmNscrolledWindowMarginHeight, (XtArgVal)10);
XmxSetArg (XmNcursorPositionVisible, (XtArgVal)True);
XmxSetArg (XmNeditable, (XtArgVal)False);
XmxSetArg (XmNeditMode, (XtArgVal)XmMULTI_LINE_EDIT);
XmxSetArg (XmNrows, (XtArgVal)15);
XmxSetArg (XmNcolumns, (XtArgVal)80);
XmxSetArg (XmNwordWrap, (XtArgVal)True);
XmxSetArg (XmNscrollHorizontal, (XtArgVal)False);
win->mailto_form_text = XmxMakeScrolledText (mailto_form_form);
dialog_sep = XmxMakeHorizontalSeparator (mailto_form_form);
/* create from, to, and subject widgets */
fromlabel = XmxMakeLabel(mailto_form_form, "From:");
XmxSetArg (XmNeditable, (XtArgVal)False);
win->mailto_form_fromfield = XmxMakeTextField(mailto_form_form);
tolabel = XmxMakeLabel(mailto_form_form, "To:");
XmxSetArg (XmNeditable, (XtArgVal)False);
win->mailto_form_tofield = XmxMakeTextField(mailto_form_form);
sublabel = XmxMakeLabel(mailto_form_form, "Subject:");
XmxSetArg (XmNeditable, (XtArgVal)False);
win->mailto_form_subfield = XmxMakeTextField(mailto_form_form);
/* constraints for FROM */
XmxSetOffsets(fromlabel, 14, 10, 10, 10);
XmxSetConstraints
(fromlabel, XmATTACH_FORM, XmATTACH_NONE, XmATTACH_FORM,
XmATTACH_NONE, NULL, NULL, NULL, NULL);
XmxSetOffsets(win->mailto_form_fromfield, 10, 10, 10, 10);
XmxSetConstraints
(win->mailto_form_fromfield, XmATTACH_FORM, XmATTACH_NONE, XmATTACH_WIDGET,
XmATTACH_FORM, NULL, NULL, fromlabel, NULL);
/* constraints for TO */
XmxSetOffsets(tolabel, 14, 10, 10, 10);
XmxSetConstraints
(tolabel, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_NONE,
win->mailto_form_fromfield, NULL, NULL, NULL);
XmxSetOffsets(win->mailto_form_tofield, 10, 10, 10, 10);
XmxSetConstraints
(win->mailto_form_tofield, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_WIDGET,
XmATTACH_FORM, win->mailto_form_fromfield, NULL, tolabel, NULL);
/* constraints for SUBJECT */
XmxSetOffsets(sublabel, 14, 10, 10, 10);
XmxSetConstraints
(sublabel, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM,
XmATTACH_NONE, win->mailto_form_tofield, NULL, NULL, NULL);
XmxSetOffsets(win->mailto_form_subfield, 10, 10, 10, 10);
XmxSetConstraints
(win->mailto_form_subfield, XmATTACH_WIDGET, XmATTACH_NONE,
XmATTACH_WIDGET, XmATTACH_FORM, win->mailto_form_tofield, NULL,
sublabel, NULL);
/* create buttons */
buttons_form = XmxMakeFormAndThreeButtons
(mailto_form_form, mailto_form_win_cb,
"Send", "Dismiss", "Help...",
0, 1, 2);
XmxSetOffsets (XtParent (win->mailto_form_text), 3, 0, 3, 3);
XmxSetConstraints
(XtParent (win->mailto_form_text), XmATTACH_WIDGET, XmATTACH_WIDGET,
XmATTACH_FORM, XmATTACH_FORM,
win->mailto_form_subfield, dialog_sep, NULL, NULL);
XmxSetArg (XmNtopOffset, (XtArgVal)10);
XmxSetConstraints
(dialog_sep, XmATTACH_NONE, XmATTACH_WIDGET, XmATTACH_FORM,
XmATTACH_FORM,
NULL, buttons_form, NULL, NULL);
XmxSetConstraints
(buttons_form, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_FORM,
XmATTACH_FORM, NULL, NULL, NULL, NULL);
}
/* fill in text fields */
sprintf(namestr, "%s <%s>", get_pref_string(eDEFAULT_AUTHOR_NAME),
get_pref_string(eDEFAULT_AUTHOR_EMAIL));
XmxTextSetString (win->mailto_form_fromfield, namestr);
XmxTextSetString (win->mailto_form_tofield, to_address);
if (subject != NULL)
XmTextFieldSetString(win->mailto_form_subfield,subject);
else
XmTextFieldSetString(win->mailto_form_subfield,"");
win->post_data=strdup(post_data);
buf=makeReadable(post_data,1);
XmTextSetString (win->mailto_form_text, buf);
if (buf) {
free(buf);
}
XmTextSetInsertionPosition (win->mailto_form_text, 0);
XmxManageRemanage (win->mailto_form_win);
return mo_succeed;
}
/* SWP -- 11.15.95 -- ACTION=mailto support for Forms */
void do_mailto_post(mo_window *win, char *to, char *from, char *subject, char *body) {
if (!win || !win->current_node || !win->current_node->url ||
!*(win->current_node->url) || !to || !*to || !from || !*from ||
!body || !*body || !subject || !*subject) {
return;
}
if (!strcmp(post_content_type,"text/plain")) {
char *buf=NULL;
buf=makeReadable(body,0);
#ifndef DISABLE_TRACE
if (srcTrace) {
fprintf(stderr,"To: [%s]\nFrom: [%s]\nSubj: [%s]\nBody: [%s]\n",to,from,subject,buf);
}
#endif
mo_send_mailto_message(buf, to, subject, post_content_type,
win->current_node->url);
if (buf) {
free(buf);
}
}
else {
#ifndef DISABLE_TRACE
if (srcTrace) {
fprintf(stderr,"To: [%s]\nFrom: [%s]\nSubj: [%s]\nBody: [%s]\n",to,from,subject,body);
}
#endif
mo_send_mailto_message(body, to, subject, post_content_type,
win->current_node->url);
}
return;
}
/* ------------------------------------------------------------------------ */
/* these are not currently used. We just use the functions in techsupport.c */
/* ------------------------------------------------------------------------ */
static FILE *_fp = NULL;
FILE *mo_start_sending_mailto_message (char *to, char *subj,
char *content_type, char *url)
{
char cmd[2048];
/* char *tmp;*/
if (!to)
return NULL;
if (get_pref_string(eMAIL_FILTER_COMMAND))
{
sprintf (cmd, "%s | %s", get_pref_string(eMAIL_FILTER_COMMAND),
get_pref_string(eSENDMAIL_COMMAND));
}
else
{
sprintf (cmd, "%s", get_pref_string(eSENDMAIL_COMMAND));
}
if ((_fp = popen (cmd, "w")) == NULL)
return NULL;
fprintf (_fp, "To: %s\n", to);
fprintf (_fp, "Subject: %s\n", subj);
fprintf (_fp, "Content-Type: %s\n", content_type);
fprintf (_fp, "Mime-Version: 1.0\n");
fprintf (_fp, "X-Mailer: NCSA Mosaic %s on %s\n",
MO_VERSION_STRING, MO_MACHINE_TYPE);
if (url)
fprintf (_fp, "X-URL: %s\n", url);
fprintf (_fp, "\n");
/* Stick in BASE tag as appropriate. */
if (url && content_type &&
strcmp (content_type, "text/x-html") == 0)
fprintf (_fp, "<base href=\"%s\">\n", url);
return _fp;
}
mo_status mo_finish_sending_mailto_message (void)
{
if (_fp)
pclose (_fp);
_fp = NULL;
return mo_succeed;
}
/* ------------------------------------------------------------------------ */
mo_status mo_send_mailto_message (char *text, char *to, char *subj,
char *content_type, char *url)
{
FILE *fp;
fp = mo_start_sending_mailto_message (to, subj, content_type, url);
if (!fp)
return mo_fail;
fputs (text, fp);
mo_finish_sending_mailto_message ();
return mo_succeed;
}