-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.bbj
2792 lines (2560 loc) · 124 KB
/
email.bbj
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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
rem /**
rem * Provides BBj access to email functionality
rem * @since 10.0
rem */
rem package Email
REM declare EmailDialog emailDialog!
REM emailDialog! = new EmailDialog()
REM emailDialog!.doModal()
REM release
rem ----------------------------------------------------------------------
rem Initialize
rem ----------------------------------------------------------------------
input "host? ",mailhost$
input "user? ",username$
input "pass? ",password$
input "smtp? ",smtp$; rem ' smtp or smtps
rem ' Port is usually 25 or 587
input "port? ",mailport; if mailport=0 then mailport=25
input "from? ",from$
input "subj? ",subj$
input " to? ",to$
input " cc? ",cc$
replyTo$ = ""
channel = unt
open (channel)pgm(-1)
file$ = fid(channel)(9)
close (channel)
rem ----------------------------------------------------------------------
rem Send email
rem ----------------------------------------------------------------------
if username$="" and password$="" then
mail! = new Email(mailhost$,mailport)
else
mail! = new Email(mailhost$,mailport,username$,password$,smtp$)
endif
mail!.setSubject(subj$)
mail!.setSentDate(new Date())
mail!.setFrom(from$)
mail!.setTo(to$)
if len(cc$) then mail!.setCc(cc$)
if len(replyTo$) then mail!.setReplyTo(replyTo$)
mail!.addData("<html> <TABLE border=""1""> <caption> Amount and type of Jello consumed </caption> <TR> <TH id=""t1"" >Name</TH> <TH id=""t2"" >Serving Size (oz)</TH> <TH id=""t3"" abbr=""Type"">Type of Jello</TH> <TH id=""t4"" >Seconds</TH> </TR> <TR> <TD headers=""t1"" >George</TD> <TD headers=""t2"" >10</TD> <TD headers=""t3"" >Red</TD> <TD headers=""t4"" >No</TD> </TR> <TR> <TD headers=""t1"" >Bob</TD> <TD headers=""t2"" >5</TD> <TD headers=""t3"" >Green</TD> <TD headers=""t4"" >Yes</TD> </TR> </TABLE></HTML>","text/html")
mail!.addText("Mail test")
mail!.addFile(file$)
mail!.setHeader("X-Mailer","BBj")
mail!.send()
stop
rem ----------------------------------------------------------------------
rem Use stateemnts
rem ----------------------------------------------------------------------
use ::bbtranslator.bbj::BBTranslationBundle
use ::bbtranslator.bbj::BBTranslations
use ::bbtranslator.bbj::BBTranslator
use ::bbwindowutils.bbj::BBWindowUtils
use java.io.FileInputStream
use java.io.IOException
use java.io.File
use java.lang.reflect.Array
use java.lang.Class
use java.lang.System
use java.util.Date
use java.util.Properties
use java.util.HashMap
use java.util.Set
use java.util.Iterator
use java.util.StringTokenizer
use javax.activation.DataHandler
use javax.mail.Address
use javax.mail.Multipart
use javax.mail.Message.RecipientType
use javax.mail.Session
use javax.mail.Transport
use javax.mail.internet.InternetAddress
use javax.mail.internet.MimeBodyPart
use javax.mail.internet.MimeMessage
use javax.mail.internet.MimeMultipart
use javax.mail.util.ByteArrayDataSource
rem /** Email
rem * Allows for the sending of email messages, leaving the means by which the message
rem * is populated and sent up to the caller. Attachments are supported.
rem * @since 10.0
rem * @see <a href="EmailExample.bbj">Example</a>
rem */
REM I put an extra comment here
class public Email
rem /** Session object */
field public Session session!
rem /** MimeMessage object */
field public MimeMessage message!
rem /** Multipart object */
field public Multipart multipart!
rem /** Mail server protocol, which can be smtp or smtps */
field public BBjString protocol$ = "smtp"
rem /** Mail server host */
field public BBjString mailhost$ = ""
rem /** Mail server port, default = 25 */
field public BBjNumber mailport = 25
rem /** User name to use for authentication to the mail server */
field public BBjString username$ = ""
rem /** Password to use for authentication to the mail server */
field public BBjString password$ = ""
rem /** To email addresses */
field private BBjVector ToEmailAddresses! = BBjAPI().makeVector()
rem /** Cc email addresses */
field private BBjVector CcEmailAddresses! = BBjAPI().makeVector()
rem /** Bcc email addresses */
field private BBjVector BccEmailAddresses! = BBjAPI().makeVector()
rem /** a BBjVector for inline Images */
field private BBjVector attachments! = BBjAPI().makeVector()
rem /** Multipart object */
field public Multipart relatedPart!
rem /** Constructor
rem * Constructs a Email given a host and a port
rem * @param mailhost$ Mail server host
rem * @param mailport$ Mail server port
rem */
method public Email(BBjString mailhost$, BBjNumber mailport)
#mailhost$ = mailhost$
#mailport = mailport
properties! = new Properties()
properties!.put("mail.transport.protocol","smtp")
properties!.put("mail.smtp.host",mailhost$)
properties!.put("mail.smtp.port",str(mailport))
#session! = cast(Session,Session.getInstance(properties!,null()))
#session!.setDebug(0)
#multipart! = cast(Multipart,new MimeMultipart())
#message! = cast(MimeMessage,new MimeMessage(#session!))
methodend
rem /** Constructor
rem * Constructs a Email given a host, port, user name, password, and protocol
rem * @param mailhost$ Mail server host
rem * @param mailport$ Mail server port
rem * @param username$ User name used to authenticate to mail server
rem * @param password$ Password used to authenticate to mail server
rem * @param smtp$ Protocol to use to mail server, which can be smtp or smtps
rem */
method public Email(BBjString mailhost$, BBjNumber mailport, BBjString username$, BBjString password$, BBjString smtp$)
#protocol$ = smtp$
#mailhost$ = mailhost$
#mailport = mailport
#username$ = username$
#password$ = password$
properties! = new Properties()
properties!.put("mail.transport.protocol",smtp$)
properties!.put("mail."+smtp$+".host",mailhost$)
properties!.put("mail."+smtp$+".port",str(mailport))
properties!.put("mail."+smtp$+".auth","true")
properties!.put("mail."+smtp$+".starttls.enable", "true")
#session! = cast(Session,Session.getInstance(properties!,null()))
#session!.setDebug(0)
#multipart! = cast(Multipart,new MimeMultipart())
#message! = cast(MimeMessage,new MimeMessage(#session!))
methodend
rem /** setSentDate
rem * Sets the "sent date" field in an email's header before the email is sent. <p>
rem * It is not necessary to call this method unless some date other than the current
rem * date needs to be specified as the sent date. Changing this date will not change
rem * the actual time at which the email is sent. i.e., setting the sent date forward
rem * a day in the future will not cause the sending of the email to be delayed a day.
rem * @param date! Sent date
rem */
method public void setSentDate(Date date!)
#message!.setSentDate(date!)
methodend
rem /** setSubject
rem * Sets the subject of the email message represented by the email object
rem * @param subject$ Subject of email
rem */
method public void setSubject(BBjString subject$)
#message!.setSubject(subject$)
methodend
rem /** setFrom
rem * Sets the "from" field in an email's header before the email is sent. The "from"
rem * field indicates the sending email address. <p>
rem * Depending on the mail service provider, it may not be necessary to set this field.
rem * The value can be determined from the email account from which the mail was sent.
rem * @param from$ From email address
rem */
method public void setFrom(BBjString from$)
#message!.setFrom(new InternetAddress(from$))
methodend
rem /** setReplyTo
rem * Sets the "reply to" field in an email's header before the email is sent. The "reply to"
rem * field indicates to what email address a reply should be sent. <p>
rem * This method is optional. Replies will be directed to the from address if this value is not set
rem * @param replyTo$ Reply to email address
rem */
method public void setReplyTo(BBjString replyTo$)
replyTo! = Array.newInstance(Class.forName("javax.mail.internet.InternetAddress"),1)
Array.set(replyTo!,0,new InternetAddress(replyTo$))
#message!.setReplyTo(replyTo!)
methodend
rem /** setTo
rem * Sets the "to" field in an email's header before the email is sent. This value specifies the
rem * email address to which the message will be delivered. <p>
rem * This method only supports one email address. Add additional recipients using the addTo() method.
rem * @param to$ To email address
rem */
method public void setTo(BBjString to$)
#ToEmailAddresses!.clear()
#ToEmailAddresses!.add(to$)
methodend
rem /** addTo
rem * Sets the first recipient or adds an additional recipient to the "to" field in an email's header
rem * before the email is sent. This value specifies the email addresses to which the message will be delivered. <p>
rem * Each invocation of this method takes one email address. Calling this method multiple times will construct a
rem * list of addresses that the message will be sent to.
rem * @param to$ To email address to add
rem */
method public void addTo(BBjString to$)
#ToEmailAddresses!.add(to$)
methodend
rem /** addTo
rem * Adds recipients to the "to" field in an email's header before the email is sent.
rem * @param toAddresses! BBjVector of email address to add
rem */
method public void addTo(BBjVector toAddresses!)
if (toAddresses! <> null())
#ToEmailAddresses!.addAll(toAddresses!)
endif
methodend
rem /** setCc
rem * Sets the recipient for the carbon copy field in an email's header before the email is sent.
rem * This value specifies the email address to receive a copy of the message. <p>
rem * This method takes one email address. To specify multiple recipients for the "cc" field,
rem * use multiple invocations of the addCc() method. The cc field is visible to all email recipients.
rem * To hide addresses that emails are being sent to, consider the setBcc() and addBcc() methods. <p>
rem * Adding a recipient to the carbon copy field is the same as adding it to the "to" field.
rem * Entering the recipient in the "cc" field rather than the "to" field indicates that the message is
rem * relevant to them, but is not a direct correspondence with them.
rem * @param cc$ Cc email address
rem */
REM I put another comment here
method public void setCc(BBjString cc$)
#CcEmailAddresses!.clear()
#CcEmailAddresses!.add(cc$)
methodend
rem /** addCc
rem * Sets the first recipient or adds an additional recipient to the "cc" field in an email's header
rem * before the email is sent. This value specifies the email addresses to receive a copy of the message.<p>
rem * Each invocation of this method takes one email address. Calling this method multiple times will construct
rem * a list of addresses to receive a copy of the message. <p>
rem * Adding a recipient to the "cc"" field is the same as adding it to the "to" field. Adding the recipient in
rem * the "cc" field rather than the "to" field indicates that the message is relevant to them, but is not a direct
rem * correspondence with them.
rem * @param cc$ Cc email address to add
rem */
method public void addCc(BBjString cc$)
#CcEmailAddresses!.add(cc$)
methodend
rem /** addCc
rem * Adds recipients to the "cc" field in an email's header before the email is sent.
rem * @param ccAddresses! BBjVector of email address to add
rem */
method public void addCc(BBjVector ccAddresses!)
if (ccAddresses! <> null())
#CcEmailAddresses!.addAll(ccAddresses!)
endif
methodend
rem /** setBcc
rem * Sets the recipient for the blind carbon copy field in an email's header before the email is sent. This value
rem * specifies the email address to receive a copy of the message. Other recipients of the message will not be able
rem * to see that the email was sent to the specified recipient. <p>
rem * This method takes one email address. To specify multiple recipients for the "bcc" field, use multiple invocations
rem * of the addBcc() method. Adding a recipient to the "bcc" field (and not including that address in the "to" and "cc"
rem * fields) hides that recipient's address from all other recipients.
rem * @param bcc$ Bcc email address
rem */
method public void setBcc(BBjString bcc$)
#BccEmailAddresses!.clear()
#BccEmailAddresses!.add(bcc$)
methodend
rem /** addBcc
rem * Sets the first recipient or an additional recipient to the blind carbon copy field in an email's header before
rem * the email is sent. This value specifies the email address to receive a copy of the message. Other recipients of
rem * the message will not be able to see that the email was sent to the specified recipient. <p>
rem * Each invocation of this method takes one email address. Calling this method multiple times will construct a list
rem * of addresses to receive a copy of the message. <p>
rem * Adding a recipient to the "bcc" field is not the same as adding them to the "to" field as all other recipients,
rem * including those in the "to" and "cc" fields, will not see the entries in the "bcc" field.
rem * @param bcc$ Bcc email address to add
rem */
method public void addBcc(BBjString bcc$)
#BccEmailAddresses!.add(bcc$)
methodend
rem /** addBcc
rem * Adds recipients to the "bcc" field in an email's header before the email is sent.
rem * @param bccAddresses! BBjVector of email address to add
rem */
method public void addBcc(BBjVector bccAddresses!)
if (bccAddresses! <> null())
#BccEmailAddresses!.addAll(bccAddresses!)
endif
methodend
rem /** setText
rem * Sets the text for the body of the email message <p>
rem * Alias of addText(). Can be called multiple times to add multiple text parts to the email message.
rem * @param text$ Text to set
rem */
method public void setText(BBjString text$)
#addText(text$)
methodend
rem /** addText
rem * Sets the text for the body of the email message represented by the email object <p>
rem * May be called once or multiple times to add plain text to the body of the email message.
rem * Text will be added cumulatively
rem * @param text$ Text to add
rem */
method public void addText(BBjString text$)
mimeBodyPart! = new MimeBodyPart()
mimeBodyPart!.setText(text$)
#multipart!.addBodyPart(mimeBodyPart!)
methodend
rem /** addData
rem * Adds data to the body of the message allowing the mime type to be specified. <p>
rem * May be called once or multiple times to add data to the body of the email message.
rem * Data will be added cumulatively
rem * @param data$ Data to add
rem * @param mime$ Mime type of data
rem */
method public void addData(BBjString data$, BBjString mime$)
mimeBodyPart! = new MimeBodyPart()
mimeBodyPart!.setDataHandler(new DataHandler(new ByteArrayDataSource(data$,mime$)))
#multipart!.addBodyPart(mimeBodyPart!)
methodend
rem /** addData
rem * Adds data to the body of the message allowing the mime type to be specified. <p>
rem * May be called once or multiple times to add data to the body of the email message.
rem * Data will be added cumulatively
rem * @param fis! FileInputStream object which contains the data to add to the email
rem * @param mime$ Mime type of data
rem */
method public void addData(FileInputStream fis!, BBjString mime$)
mimeBodyPart! = new MimeBodyPart()
mimeBodyPart!.setDataHandler(new DataHandler(new ByteArrayDataSource(fis!,mime$)))
#multipart!.addBodyPart(mimeBodyPart!)
methodend
rem /** setHtml
rem * Sets the html for the email
rem * @param html$ HTML formatted string to add to the email
rem * @param basedir$ Specifies the base directory to find HTML referenced files such as images
rem */
method public void setHtml(BBjString html$, BBjString basedir$)
tmp$=html$
count=1
while pos("<img"=cvs(tmp$,8)) >0
imgtag$=tmp$(pos("<img"=cvs(tmp$,8)))
imgtag$=imgtag$(1,pos(">"=imgtag$))
tmp$=tmp$(pos("<img"=cvs(tmp$,8))+len(imgtag$))
if pos("src"=cvs(imgtag$,8))=0 then
continue
else
img$=imgtag$(pos("src"=cvs(imgtag$,8))+4)
while pos(img$(1,1)="0123456789/_-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")=0
img$=img$(2)
wend
for i=1 to len(img$)
if pos(img$(i,1)="0123456789/_-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.")=0 then
img$=img$(1,i-1)
break
fi
next
fi
#addFile(basedir$+img$,"<img_"+str(count)+">")
html$=html$(1,pos(img$=html$)-1)+"cid:img_"+str(count)+html$(pos(img$=html$)+len(img$))
count=count+1
wend
#addData(html$,"text/html")
methodend
rem /** addFile
rem * Adds a file attachment to the email message <p>
rem * May be called once or multiple times to add file attachments to the email message.
rem * @param filename$ Path to file to add to the email
rem */
method public void addFile(BBjString filename$)
mimeBodyPart! = new MimeBodyPart()
mimeBodyPart!.attachFile(new File(filename$))
#multipart!.addBodyPart(mimeBodyPart!)
methodend
rem /** addFile
rem * Adds a file attachment to the email message <p>
rem * May be called once or multiple times to add file attachments to the email message.
rem * @param filename$ Path to file to add to the email
rem * @param contentID$ Specifies the Content=ID header for the file
rem */
method public void addFile(BBjString filename$, BBjString contentID$)
mimeBodyPart! = new MimeBodyPart()
mimeBodyPart!.attachFile(new File(filename$))
mimeBodyPart!.addHeader("Content-ID",contentID$)
#multipart!.addBodyPart(mimeBodyPart!)
methodend
rem /** addImageInline
rem * Adds an image to the email in such a way that it can be inlined into the HTML conteny.
rem * @param filename$ Path to image file to add to the email
rem * @param contentID$ Specifies the Content=ID header for the file
rem * @param mime$ Specifies the mime type of the image
rem */
method public void addImageInline(BBjString filename$, BBjString contentID$, BBjString mime$)
if #relatedPart! = null() then
#relatedPart! = new MimeMultipart("related")
endif
attachment! = new MimeBodyPart()
fds! = new FileDataSource(filename$)
attachment!.setDataHandler(new DataHandler(fds!))
attachment!.addHeader("Content-ID","<" + contentID$ + ">")
attachment!.addHeader("Content-Type",mime$)
attachment!.setDisposition(MimeBodyPart.INLINE)
#attachments!.add(attachment!)
methodend
rem /** setHeader
rem * Sets various attributes of the email header <p>
rem * The basic attributes of an email header are laid out in RFC 822, which can be found at http://www.faqs.org/rfcs/rfc822.html.
rem * @param header$ Header key
rem * @param value$ Header value
rem */
method public void setHeader(BBjString header$, BBjString value$)
#message!.setHeader(header$,value$)
methodend
rem /** send
rem * Sends an email message once it has been configured.<p>
rem * At the very least, a mail server, username, password, and the "to" field (specified by the setTo() or addTo() methods)
rem * must be set before an email message can be sent. Any errors will be thrown.
rem */
method public void send()
seterr sendError
rem Add recipients to the message
#addRecipients(#ToEmailAddresses!,RecipientType.TO)
#addRecipients(#CcEmailAddresses!,RecipientType.CC)
#addRecipients(#BccEmailAddresses!,RecipientType.BCC)
if #relatedPart! <> null() then
wrap! = new MimeBodyPart()
wrap!.setContent(#multipart!)
#relatedPart!.addBodyPart(wrap!)
for i = 0 to #attachments!.size()-1
#relatedPart!.addBodyPart(cast(MimeBodyPart,#attachments!.get(i)))
next i
#message!.setContent(#relatedPart!)
else
#message!.setContent(#multipart!)
endif
if len(#username$) or len(#password$) then
Transport! = #session!.getTransport(#protocol$)
Transport!.connect(#mailhost$,#mailport,#username$,#password$)
Transport!.sendMessage(#message!,#message!.getAllRecipients())
Transport!.close()
else
Transport.send(#message!)
endif
methodret
sendError:
throw errmes(-1),err
methodend
method protected void addRecipients(BBjVector p_emailAddresses!, RecipientType p_recipientType!)
if (p_emailAddresses! <> null() and !p_emailAddresses!.isEmpty())
emailAddresses! = Array.newInstance(Class.forName("javax.mail.internet.InternetAddress"),p_emailAddresses!.size())
for i = 0 to p_emailAddresses!.size() -1
emailAddress$ = str(p_emailAddresses!.get(i))
Array.set(emailAddresses!,i,new InternetAddress(emailAddress$))
next i
#message!.addRecipients(p_recipientType!,emailAddresses!)
endif
methodend
classend
rem /** EmailDialog
rem * Displays a dialog which allows users to send emails and maintain email settings and contacts
rem * @since 14.0
rem * @see <a href="EmailDialogExample.bbj">Example</a>
rem */
class public EmailDialog
rem /** BBjAPI object */
field protected static BBjAPI API!=BBjAPI()
rem /** BBjSysGui object */
field protected BBjSysGui SysGui!
rem /** BBjThinClient object */
field protected static BBjThinClient ThinClient!=#API!.getThinClient()
rem /** BBjImageManager object */
field protected BBjImageManager ImageManager!
rem /** Translation bundle */
field protected static BBTranslationBundle TranslationBundle!=BBTranslationBundle.getBundle("email",System.getProperty("basis.BBjHome")+"/utils/email/prop")
rem /** Translations */
field protected static BBTranslations Translations!=#TranslationBundle!.getTranslations(BBTranslator.createLocale(#ThinClient!.getClientLocale()))
rem /** Client file system */
field protected BBjClientFileSystem ClientFileSystem!
rem /** Remote client */
field protected BBjNumber RemoteClient=0
rem /** Skip address focus */
field protected BBjNumber SkipAddressFocus=0
rem /** Email dialog */
field protected BBjTopLevelWindow EmailWindow!
rem /** Email dialog title */
field protected BBjString Title$
rem /** Email dialog cancel button */
field protected BBjButton EmailCancelButton!
rem /** Email dialog send button */
field protected BBjButton EmailSendButton!
rem /** Email dialog settings button */
field protected BBjButton EmailSettingsButton!
rem /** Email dialog to menu button */
field protected BBjMenuButton EmailToMenuButton!
rem /** Email dialog to popup menu*/
field protected BBjPopupMenu EmailToPopupMenu!
rem /** Email dialog CC show menu item */
field protected BBjMenuItem EmailCCAddMenuItem!
rem /** Email dialog BCC show menu item */
field protected BBjMenuItem EmailBCCAddMenuItem!
rem /** Email dialog CC menu button */
field protected BBjMenuButton EmailCCMenuButton!
rem /** Email dialog CC popup menu*/
field protected BBjPopupMenu EmailCCPopupMenu!
rem /** Email dialog CC hide menu item */
field protected BBjMenuItem EmailCCRemoveMenuItem!
rem /** Email dialog BBC menu button */
field protected BBjMenuButton EmailBCCMenuButton!
rem /** Email dialog BCC popup menu*/
field protected BBjPopupMenu EmailBCCPopupMenu!
rem /** Email dialog BCC hide menu item */
field protected BBjMenuItem EmailBCCRemoveMenuItem!
rem /** Email dialog to edit box */
field protected BBjEditBox EmailToEditBox!
rem /** Email dialog CC edit box */
field protected BBjEditBox EmailCCEditBox!
rem /** Email dialog BCC edit box */
field protected BBjEditBox EmailBCCEditBox!
rem /** Email dialog subject static text */
field protected BBjStaticText EmailSubjectStaticText!
rem /** Email dialog subject edit box */
field protected BBjEditBox EmailSubjectEditBox!
rem /** Email dialog message static text */
field protected BBjStaticText EmailMessageStaticText!
rem /** Email dialog message cedit */
field protected BBjCEdit EmailMessageCEdit!
rem /** Email dialog Attachment menu button */
field protected BBjMenuButton EmailAttachmentMenuButton!
rem /** Email dialog Attachment popup menu*/
field protected BBjPopupMenu EmailAttachmentPopupMenu!
rem /** Email dialog Attachment client hide menu item */
field protected BBjMenuItem EmailAttachmentClientMenuItem!
rem /** Email dialog Attachment slient hide menu item */
field protected BBjMenuItem EmailAttachmentServerMenuItem!
rem /** Email dialog Row */
field protected BBjNumber EmailDialogRow
rem /** Email dialog CC enabled flag */
field protected BBjNumber EmailCCEnabled
rem /** Email dialog BCC enabled flag */
field protected BBjNumber EmailBCCEnabled
rem /** Email dialog addresses list box */
field protected BBjListBox EmailAddressesListBox!
rem /** Email dialog remove image */
field protected BBjImage RemoveImage!
rem /** Email dialog attachment image */
field protected BBjImage AttachmentImage!
rem /** Attachment dialog */
field protected BBjTopLevelWindow AttachmentDialog!
rem /** Attachment file chooser */
field protected BBjFileChooser AttachmentFileChooser!
rem /** Attachment folder */
field protected BBjString AttachmentFolder$
rem /** Email settings dialog */
field protected BBjTopLevelWindow EmailSettingsDialog!
rem /** Email settings dialog cancel button */
field protected BBjButton EmailSettingsCancelButton!
rem /** Email settings dialog save button */
field protected BBjButton EmailSettingsSaveButton!
rem /** Email settings dialog from edit box */
field protected BBjEditBox EmailSettingsFromEditBox!
rem /** Email settings dialog server edit box */
field protected BBjEditBox EmailSettingsServerEditBox!
rem /** Email settings dialog port edit box */
field protected BBjEditBox EmailSettingsPortEditBox!
rem /** Email settings dialog SSL check box */
field protected BBjCheckBox EmailSettingsSSLCheckBox!
rem /** Email settings dialog user name edit box */
field protected BBjEditBox EmailSettingsUserNameEditBox!
rem /** Email settings dialog password edit box */
field protected BBjEditBox EmailSettingsPasswordEditBox!
rem /** Email settings dialog create contacts on send check box */
field protected BBjCheckBox EmailSettingsCreateContactsOnSendCheckBox!
rem /** Contacts dialog */
field protected BBjTopLevelWindow ContactsDialog!
rem /** Contacts dialog select button */
field protected BBjButton ContactsSelectButton!
rem /** Contacts dialog cancel button */
field protected BBjButton ContactsCancelButton!
rem /** Contacts dialog new button */
field protected BBjButton ContactsNewButton!
rem /**Contacts dialog remove button */
field protected BBjButton ContactsRemoveButton!
rem /** Contacts dialog edit button */
field protected BBjButton ContactsEditButton!
rem /** Contacts dialog grid */
field protected BBjStandardGrid ContactsGrid!
rem /** Contact change dialog */
field protected BBjTopLevelWindow ContactChangeDialog!
rem /** Contact change email edit box */
field protected BBjEditBox ContactChangeEmailEditBox!
rem /** Contact change first name edit box */
field protected BBjEditBox ContactChangeFirstNameEditBox!
rem /** Contact change last name edit box */
field protected BBjEditBox ContactChangeLastNameEditBox!
rem /** Contact change save button */
field protected BBjButton ContactChangeSaveButton!
rem /** Contact change cancel button */
field protected BBjButton ContactChangeCancelButton!
rem /** Contact change edit flag */
field protected BBjNumber ContactChangeEdit
rem /** Contact change first name */
field protected BBjString ContactChangeFirstName$
rem /** Contact change last name */
field protected BBjString ContactChangeLastName$
rem /** Contact change email */
field protected BBjString ContactChangeEmail$
rem /** Email addresses vector */
field protected BBjVector EmailAddressesVector!
rem /** Contacts HashMap */
field protected HashMap EmailContactsHashMap!
rem /** Email To addresses Vector */
field protected BBjVector EmailToVector!
rem /** Email CC addresses Vector */
field protected BBjVector EmailCCVector!
rem /** Email BCC addresses Vector */
field protected BBjVector EmailBCCVector!
rem /** Email subject */
field protected BBjString EmailSubject$
rem /** Email Message */
field protected BBjString EmailMessage$
rem /** Email Attachments */
field protected HashMap EmailAttachmentsHashMap!
rem /** Email From address */
field protected BBjString EmailFrom$
rem /** Email server hostname */
field protected BBjString EmailServerHost$="smtp.gmail.com"
rem /** Email server port */
field protected BBjNumber EmailServerPort=465
rem /** Email server SSL */
field protected BBjNumber EmailServerSSL=1
rem /** User name for email server */
field protected BBjString EmailServerUserName$
rem /** Password for email server */
field protected BBjString EmailServerPassword$
rem /** Create contacts on send */
field protected BBjNumber CreateContactsOnSend=1
rem /** Close dialog on send */
field protected BBjNumber CloseOnSend=1
rem /** Constant that represents a email To address type */
field public static BBjNumber EMAIL_TO_TYPE=0
rem /** Constant that represents a email CC address type */
field public static BBjNumber EMAIL_CC_TYPE=1
rem /** Constant that represents a email BCC address type */
field public static BBjNumber EMAIL_BCC_TYPE=2
rem /** Translated text for Email */
field protected static BBjString EMAIL$=#Translations!.getTranslation("EMAIL")
rem /** Translated text for To */
field protected static BBjString TO$=#Translations!.getTranslation("TO")
rem /** Translated text for CC */
field protected static BBjString CC$=#Translations!.getTranslation("CC")
rem /** Translated text for BCC */
field protected static BBjString BCC$=#Translations!.getTranslation("BCC")
rem /** Translated text for Subject */
field protected static BBjString SUBJECT$=#Translations!.getTranslation("SUBJECT")
rem /** Translated text for Message */
field protected static BBjString MESSAGE$=#Translations!.getTranslation("MESSAGE")
rem /** Translated text for attach server files */
field protected static BBjString ATTACH_SERVER_FILES$=#Translations!.getTranslation("ATTACH_SERVER_FILES")
rem /** Translated text for attach client files */
field protected static BBjString ATTACH_CLIENT_FILES$=#Translations!.getTranslation("ATTACH_CLIENT_FILES")
rem /** Translated text for Settings */
field protected static BBjString SETTINGS$=#Translations!.getTranslation("SETTINGS")
rem /** Translated text for Cancel */
field protected static BBjString CANCEL$=#Translations!.getTranslation("CANCEL")
rem /** Translated text for Send */
field protected static BBjString SEND$=#Translations!.getTranslation("SEND")
rem /** Translated text for Save */
field protected static BBjString SAVE$=#Translations!.getTranslation("SAVE")
rem /** Translated text for Contacts */
field protected static BBjString CONTACTS$=#Translations!.getTranslation("CONTACTS")
rem /** Translated text for Select */
field protected static BBjString SELECT$=#Translations!.getTranslation("SELECT")
rem /** Translated text for New */
field protected static BBjString NEW$=#Translations!.getTranslation("NEW")
rem /** Translated text for Edit */
field protected static BBjString EDIT$=#Translations!.getTranslation("EDIT")
rem /** Translated text for Remove */
field protected static BBjString REMOVE$=#Translations!.getTranslation("REMOVE")
rem /** Translated text for First Name */
field protected static BBjString FIRST_NAME$=#Translations!.getTranslation("FIRST_NAME")
rem /** Translated text for Last Name */
field protected static BBjString LAST_NAME$=#Translations!.getTranslation("LAST_NAME")
rem /** Translated text for New Contact */
field protected static BBjString NEW_CONTACT$=#Translations!.getTranslation("NEW_CONTACT")
rem /** Translated text for Edit Contact */
field protected static BBjString EDIT_CONTACT$=#Translations!.getTranslation("EDIT_CONTACT")
rem /** Translated text for From Email */
field protected static BBjString FROM_EMAIL$=#Translations!.getTranslation("FROM_EMAIL")
rem /** Translated text for Server */
field protected static BBjString SERVER$=#Translations!.getTranslation("SERVER")
rem /** Translated text for Port */
field protected static BBjString PORT$=#Translations!.getTranslation("PORT")
rem /** Translated text for SSL */
field protected static BBjString SSL$=#Translations!.getTranslation("SSL")
rem /** Translated text for User Name */
field protected static BBjString USER_NAME$=#Translations!.getTranslation("USER_NAME")
rem /** Translated text for Password */
field protected static BBjString PASSWORD$=#Translations!.getTranslation("PASSWORD")
rem /** Translated text for create contacts on save */
field protected static BBjString CREATE_CONTACTS_ON_SEND$=#Translations!.getTranslation("CREATE_CONTACTS_ON_SEND")
rem /** Translated text for remove contact confirmation message */
field protected static BBjString REMOVE_CONTACT_CONFRIM_MSG$=#Translations!.getTranslation("REMOVE_CONTACT_CONFRIM_MSG")
rem /** Translated text for email sent message */
field protected static BBjString EMAIL_SENT_MSG$=#Translations!.getTranslation("EMAIL_SENT_MSG")
rem /** Translated text for email failed message */
field protected static BBjString EMAIL_FAILED_MSG$=#Translations!.getTranslation("EMAIL_FAILED_MSG")
rem /** Translated text for invalid email message */
field protected static BBjString INVALID_EMAIL_MSG$=#Translations!.getTranslation("INVALID_EMAIL_MSG")
rem /** Translated text for email attachment already message */
field protected static BBjString EMAIL_ATTACHMENT_ALREADY_ADDED_MSG$=#Translations!.getTranslation("EMAIL_ATTACHMENT_ALREADY_ADDED_MSG")
rem /** Translated text for email address already added message */
field protected static BBjString EMAIL_ADDRESS_ALREADY_ADDED_MSG$=#Translations!.getTranslation("EMAIL_ADDRESS_ALREADY_ADDED_MSG")
rem /** Translated text for contact already exists message */
field protected static BBjString CONTACT_ALREADY_EXISTS_MSG$=#Translations!.getTranslation("CONTACT_ALREADY_EXISTS_MSG")
rem /** Translated text for overwrite message */
field protected static BBjString OVERWRITE_MSG$=#Translations!.getTranslation("OVERWRITE_MSG")
rem /** Default Constructor
rem * Creates a empty EmailDialog object
rem */
method public EmailDialog()
#SysGui! = #API!.openSysGui("X0")
#ImageManager!=#SysGui!.getImageManager()
#ClientFileSystem! = #ThinClient!.getClientFileSystem()
#EmailAttachmentsHashMap! = new HashMap()
rem Remote client check
if (#ThinClient!.getClientName() <> "127.0.0.1" and info(3,4) <> info(3,7))
#RemoteClient=1
endif
rem Load contacts and settings from the user properties
#EmailContactsHashMap! = #getEmailContacts()
#EmailFrom$ = #getEmailFrom()
#EmailServerHost$ = #getEmailServerHost()
#EmailServerPort = #getEmailServerPort()
#EmailServerSSL = #getEmailServerSSL()
#EmailServerUserName$ = #getEmailServerUserName()
#EmailServerPassword$ = #getEmailServerPassword()
#CreateContactsOnSend = #getCreateContactsOnSend()
#EmailToVector! = #API!.makeVector()
#EmailCCVector! = #API!.makeVector()
#EmailBCCVector! = #API!.makeVector()
#RemoveImage! = #ImageManager!.loadImageFromFile(System.getProperty("basis.BBjHome") + "/utils/email/remove.png")
#AttachmentImage! = #ImageManager!.loadImageFromFile(System.getProperty("basis.BBjHome") + "/utils/email/paperclip.png")
rem Create the email window
#EmailWindow! = #SysGui!.addWindow(#SysGui!.getAvailableContext(),200,200,520,230,"",$00090012$)
#setTitle(#EMAIL$)
#EmailWindow!.addStyle("basisUtility")
BBWindowUtils.centerWindow(#EmailWindow!,err=*next)
#EmailToMenuButton! = #EmailWindow!.addMenuButton(#EmailWindow!.getAvailableControlID(),5,10,50,25,#TO$ + ":")
#EmailToPopupMenu! = #EmailToMenuButton!.addDropdownMenu()
#EmailCCAddMenuItem! = #EmailToPopupMenu!.addMenuItem(-201,#CC$)
#EmailBCCAddMenuItem! = #EmailToPopupMenu!.addMenuItem(-202,#BCC$)
#EmailToEditBox! = #EmailWindow!.addEditBox(#EmailWindow!.getAvailableControlID(),60,10,450,25,"")
#EmailCCMenuButton! = #EmailWindow!.addMenuButton(#EmailWindow!.getAvailableControlID(),5,40,50,25,#CC$ + ":",$0010$)
#EmailCCEditBox! = #EmailWindow!.addEditBox(#EmailWindow!.getAvailableControlID(),60,40,450,25,"",$0010$)
#EmailCCPopupMenu! = #EmailCCMenuButton!.addDropdownMenu()
#EmailCCRemoveMenuItem! = #EmailCCPopupMenu!.addMenuItem(-301,#REMOVE$)
#EmailBCCMenuButton! = #EmailWindow!.addMenuButton(#EmailWindow!.getAvailableControlID(),5,70,50,25,#BCC$ + ":",$0010$)
#EmailBCCPopupMenu! = #EmailBCCMenuButton!.addDropdownMenu()
#EmailBCCRemoveMenuItem! = #EmailBCCPopupMenu!.addMenuItem(-401,#REMOVE$)
#EmailBCCEditBox! = #EmailWindow!.addEditBox(#EmailWindow!.getAvailableControlID(),60,70,450,25,"",$0010$)
#EmailSubjectStaticText! = #EmailWindow!.addStaticText(#EmailWindow!.getAvailableControlID(),5,43,50,25,#SUBJECT$ + ":",$8000$)
#EmailSubjectEditBox! = #EmailWindow!.addEditBox(#EmailWindow!.getAvailableControlID(),60,40,450,25,"")
#EmailMessageStaticText! = #EmailWindow!.addStaticText(#EmailWindow!.getAvailableControlID(),5,70,50,25,#MESSAGE$ + ":",$8000$)
#EmailMessageCEdit! = #EmailWindow!.addCEdit(#EmailWindow!.getAvailableControlID(),60,70,450,75,"")
if (info(6,0) <> "GWT")
#EmailMessageCEdit!.setLeftMargin(5)
#EmailMessageCEdit!.setRightMargin(5)
endif
#EmailMessageCEdit!.setLineWrap(1)
#EmailMessageCEdit!.setDrawBorder(1)
#EmailMessageCEdit!.setIgnoreTabs(1)
#EmailAttachmentMenuButton! = #EmailWindow!.addMenuButton(#EmailWindow!.getAvailableControlID(),5,150,50,25,"")
#EmailAttachmentMenuButton!.setImage(#AttachmentImage!)
if (#RemoteClient)
#EmailAttachmentPopupMenu! = #EmailAttachmentMenuButton!.addDropdownMenu()
#EmailAttachmentServerMenuItem! = #EmailAttachmentPopupMenu!.addMenuItem(-501,#ATTACH_SERVER_FILES$)
#EmailAttachmentClientMenuItem! = #EmailAttachmentPopupMenu!.addMenuItem(-502,#ATTACH_CLIENT_FILES$)
endif
#EmailAddressesListBox! = #EmailWindow!.addListBox(#EmailWindow!.getAvailableControlID(),60,35,450,125,"",$0010$)
#EmailAddressesVector! = #API!.makeVector()
#EmailSettingsButton! = #EmailWindow!.addButton(#EmailWindow!.getAvailableControlID(),5,200,100,25,#SETTINGS$ + "...")
#EmailCancelButton! = #EmailWindow!.addButton(#EmailWindow!.getAvailableControlID(),310,200,100,25,#CANCEL$)
#EmailSendButton! = #EmailWindow!.addButton(#EmailWindow!.getAvailableControlID(),415,200,100,25,#SEND$)
#EmailWindow!.setCallback(BBjTopLevelWindow.ON_CLOSE,"OnEmailDialogClose")
#EmailCancelButton!.setCallback(BBjButton.ON_BUTTON_PUSH,"OnEmailDialogClose")
#EmailSettingsButton!.setCallback(BBjButton.ON_BUTTON_PUSH,#this!,"OnEmailDialogSettings")
#EmailSendButton!.setCallback(BBjButton.ON_BUTTON_PUSH,#this!,"OnEmailDialogSend")
#EmailToMenuButton!.setCallback(BBjMenuButton.ON_BUTTON_PUSH,#this!,"OnEmailDialogToContacts")
#EmailCCMenuButton!.setCallback(BBjMenuButton.ON_BUTTON_PUSH,#this!,"OnEmailDialogCCContacts")
#EmailBCCMenuButton!.setCallback(BBjMenuButton.ON_BUTTON_PUSH,#this!,"OnEmailDialogBCCContacts")
#EmailCCAddMenuItem!.setCallback(BBjMenuItem.ON_POPUP_ITEM_SELECT,#this!,"OnEmailDialogCCAdd")
#EmailBCCAddMenuItem!.setCallback(BBjMenuItem.ON_POPUP_ITEM_SELECT,#this!,"OnEmailDialogBCCAdd")
#EmailCCRemoveMenuItem!.setCallback(BBjMenuItem.ON_POPUP_ITEM_SELECT,#this!,"OnEmailDialogCCRemove")
#EmailBCCRemoveMenuItem!.setCallback(BBjMenuItem.ON_POPUP_ITEM_SELECT,#this!,"OnEmailDialogBCCRemove")
#EmailAttachmentMenuButton!.setCallback(BBjMenuButton.ON_BUTTON_PUSH,#this!,"OnEmailDialogAttachmentServer")
if (#RemoteClient)
#EmailAttachmentServerMenuItem!.setCallback(BBjMenuItem.ON_POPUP_ITEM_SELECT,#this!,"OnEmailDialogAttachmentServer")
#EmailAttachmentClientMenuItem!.setCallback(BBjMenuItem.ON_POPUP_ITEM_SELECT,#this!,"OnEmailDialogAttachmentClient")
endif
#EmailToEditBox!.setCallback(BBjEditBox.ON_EDIT_MODIFY,#this!,"OnEmailAddressEdit")
#EmailToEditBox!.setCallback(BBjEditBox.ON_EDIT_KEYPRESS,#this!,"OnEmailToAddressKeypress")
#EmailToEditBox!.setCallback(BBjEditBox.ON_LOST_FOCUS,#this!,"OnEmailAddressLostFocus")
#EmailCCEditBox!.setCallback(BBjEditBox.ON_EDIT_MODIFY,#this!,"OnEmailAddressEdit")
#EmailCCEditBox!.setCallback(BBjEditBox.ON_EDIT_KEYPRESS,#this!,"OnEmailCCAddressKeypress")
#EmailCCEditBox!.setCallback(BBjEditBox.ON_LOST_FOCUS,#this!,"OnEmailAddressLostFocus")
#EmailBCCEditBox!.setCallback(BBjEditBox.ON_EDIT_MODIFY,#this!,"OnEmailAddressEdit")
#EmailBCCEditBox!.setCallback(BBjEditBox.ON_EDIT_KEYPRESS,#this!,"OnEmailBCCAddressKeypress")
#EmailBCCEditBox!.setCallback(BBjEditBox.ON_LOST_FOCUS,#this!,"OnEmailAddressLostFocus")
#EmailAddressesListBox!.setCallback(BBjListBox.ON_LIST_DOUBLE_CLICK,#this!,"OnEmailAddressSelect")
methodend
rem /** setTitle
rem * Sets the title of the dialog
rem * @param p_title$ Sets the title of the dialog
rem */
method public void setTitle(BBjString p_title$)
#Title$ = p_title$
#EmailWindow!.setTitle(#Title$)
methodend
rem /** setLocation
rem * Sets the X,Y location of the dialog
rem * @param p_x Specifies the X location
rem * @param p_y Specifies the y location
rem */
method public void setLocation(BBjNumber p_x, BBjNumber p_y)
#EmailWindow!.setLocation(p_x,p_y)
methodend
rem /** setEmailSubject
rem * Sets the email subject
rem * @param p_emailSubject$ Email subject
rem */
method public void setEmailSubject(BBjString p_emailSubject$)
#EmailSubject$ = p_emailSubject$
methodend
rem /** setEmailMessage
rem * Sets the email message
rem * @param p_emailMessage$ Email message
rem */
method public void setEmailMessage(BBjString p_emailMessage$)
#EmailMessage$ = p_emailMessage$
methodend
rem /** addEmailAttachment
rem * Adds a file as a email attachment
rem * @param p_emailAttachment$ Location of file to add as an email attachment
rem * The attachment will only be added if the associated file can be opened
rem * @return Returns TRUE (1) if the email attachment was added or FALSE (0) otherwise
rem */
method public BBjNumber addEmailAttachment(BBjString p_emailAttachment$)
declare BBjChildWindow attachmentChildWindow!
declare BBjStaticText attachmentStaticText!
declare BBjToolButton attachmentRemoveButton!
rc = 0
chan = unt
seterr addEmailAttachmentReturn
open (chan) p_emailAttachment$
attachmentPath$ = fid(chan)(9)
close (chan)
if !(#EmailAttachmentsHashMap!.containsKey(attachmentPath$))
emailWindowHeight = #EmailWindow!.getHeight()
attachmentChildWindow! = #EmailWindow!.addChildWindow(#EmailWindow!.getAvailableControlID(),60,emailWindowHeight-80,450,25,"",$10$,#SysGui!.getAvailableContext())
attachmentStaticText! = attachmentChildwindow!.addStaticText(attachmentChildWindow!.getAvailableControlID(),5,5,420,25,"")
attachmentStaticText!.setLineWrap(0)
attachmentStaticText!.setText(attachmentPath$)
attachmentStaticText!.setShortCue(attachmentPath$)
attachmentRemoveButton! = attachmentChildwindow!.addToolButton(attachmentChildWindow!.getAvailableControlID(),427,2,21,21,"")
attachmentRemoveButton!.setNoEdge(1)
attachmentRemoveButton!.setOpaque(0)
attachmentRemoveButton!.setImage(#RemoveImage!)
attachmentRemoveButton!.setUserData(attachmentPath$)
attachmentRemoveButton!.setCallback(BBjToolButton.ON_TOOL_BUTTON_PUSH,#this!,"OnAttachmentRemove")
#EmailAttachmentsHashMap!.put(attachmentPath$,attachmentChildWindow!)
#layoutEmailDialogControls()
rc = 1
endif
addEmailAttachmentReturn:
methodret rc
methodend
rem /** removeEmailAttachment
rem * Removes a email attachment
rem * @param p_emailAttachment$ Path of file to remove from being an email attachment
rem * @return Returns TRUE (1) if the email attachment was removed or FALSE (0) otherwise
rem */
method public BBjNumber removeEmailAttachment(BBjString p_emailAttachment$)
declare BBjString fileName!
declare BBjChildWindow eamilAttachmentChildWindow!
rc = 0
chan = unt
seterr removeEmailAttachmentReturn
open (chan) p_emailAttachment$
attachmentPath$ = fid(chan)(9)
close (chan)
if (#EmailAttachmentsHashMap!.containsKey(attachmentPath$))
eamilAttachmentChildWindow! = cast(BBjChildWindow,#EmailAttachmentsHashMap!.get(attachmentPath$))
eamilAttachmentChildWindow!.destroy()
#EmailAttachmentsHashMap!.remove(attachmentPath$)
rc = 1
#layoutEmailDialogControls()
endif
removeEmailAttachmentReturn:
methodret rc
methodend
rem /** OnAttachmentRemove
rem * Callback for when a remove attachment tool button is pushed
rem * @param p_event! BBjToolButtonPushEvent object
rem */
method public void OnAttachmentRemove(BBjToolButtonPushEvent p_event!)
declare BBjToolButton removeAttachmentToolButton!
removeAttachmentToolButton! = cast(BBjToolButton,p_event!.getControl())
attachment$ = str(removeAttachmentToolButton!.getUserData())
#removeEmailAttachment(attachment$)
methodend
rem /** setEmailFrom
rem * Sets the email from address
rem * @param p_emailFrom$ From email address
rem */
method public void setEmailFrom(BBjString p_emailFrom$)
#EmailFrom$ = p_emailFrom$
#ThinClient!.setUserProperty("Email.From",#EmailFrom$)
methodend
rem /** setEmailServerHost
rem * Sets the email server host
rem * @param p_emailServerHost$ Email server host name