-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
MailWindow.cpp
3253 lines (2722 loc) · 83.1 KB
/
MailWindow.cpp
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
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2001, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
BeMail(TM), Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or
registered trademarks of Be Incorporated in the United States and other
countries. Other brand product names are registered trademarks or trademarks
of their respective holders. All rights reserved.
*/
#include "MailWindow.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <Autolock.h>
#include <Clipboard.h>
#include <Debug.h>
#include <E-mail.h>
#include <File.h>
#include <InterfaceKit.h>
#include <Locale.h>
#include <Node.h>
#include <PathMonitor.h>
#include <Roster.h>
#include <Screen.h>
#include <StorageKit.h>
#include <String.h>
#include <TextView.h>
#include <UTF8.h>
#include <fs_index.h>
#include <fs_info.h>
#include <MailMessage.h>
#include <MailSettings.h>
#include <MailDaemon.h>
#include <mail_util.h>
#include <CharacterSetRoster.h>
#include "ButtonBar.h"
#include "Content.h"
#include "Enclosures.h"
#include "FieldMsg.h"
#include "FindWindow.h"
#include "Header.h"
#include "Messages.h"
#include "MailApp.h"
#include "MailPopUpMenu.h"
#include "MailSupport.h"
#include "Prefs.h"
#include "QueryMenu.h"
#include "Signature.h"
#include "Status.h"
#include "String.h"
#include "Utilities.h"
#define B_TRANSLATION_CONTEXT "Mail"
using namespace BPrivate;
const char *kUndoStrings[] = {
"Undo",
"Undo typing",
"Undo cut",
"Undo paste",
"Undo clear",
"Undo drop"
};
const char *kRedoStrings[] = {
"Redo",
"Redo typing",
"Redo cut",
"Redo paste",
"Redo clear",
"Redo drop"
};
// Text for both the main menu and the pop-up menu.
static const char *kSpamMenuItemTextArray[] = {
"Mark as spam and move to trash", // M_TRAIN_SPAM_AND_DELETE
"Mark as spam", // M_TRAIN_SPAM
"Unmark this message", // M_UNTRAIN
"Mark as genuine" // M_TRAIN_GENUINE
};
static const uint32 kMsgQuitAndKeepAllStatus = 'Casm';
static const char *kQueriesDirectory = "mail/queries";
static const char *kAttrQueryInitialMode = "_trk/qryinitmode";
// taken from src/kits/tracker/Attributes.h
static const char *kAttrQueryInitialString = "_trk/qryinitstr";
static const char *kAttrQueryInitialNumAttrs = "_trk/qryinitnumattrs";
static const char *kAttrQueryInitialAttrs = "_trk/qryinitattrs";
static const uint32 kAttributeItemMain = 'Fatr';
// taken from src/kits/tracker/FindPanel.h
static const uint32 kByNameItem = 'Fbyn';
// taken from src/kits/tracker/FindPanel.h
static const uint32 kByAttributeItem = 'Fbya';
// taken from src/kits/tracker/FindPanel.h
static const uint32 kByForumlaItem = 'Fbyq';
// taken from src/kits/tracker/FindPanel.h
// static list for tracking of Windows
BList TMailWindow::sWindowList;
BLocker TMailWindow::sWindowListLock;
// #pragma mark -
TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
const entry_ref* ref, const char* to, const BFont* font, bool resending,
BMessenger* messenger)
:
BWindow(rect, title, B_DOCUMENT_WINDOW, 0),
fApp(app),
fMail(NULL),
fRef(NULL),
fFieldState(0),
fPanel(NULL),
fLeaveStatusMenu(NULL),
fSendButton(NULL),
fSaveButton(NULL),
fPrintButton(NULL),
fSigButton(NULL),
fZoom(rect),
fEnclosuresView(NULL),
fPrevTrackerPositionSaved(false),
fNextTrackerPositionSaved(false),
fSigAdded(false),
fReplying(false),
fResending(resending),
fSent(false),
fDraft(false),
fChanged(false),
fOriginatingWindow(NULL),
fReadButton(NULL),
fNextButton(NULL),
fDownloading(false)
{
fKeepStatusOnQuit = false;
if (messenger != NULL)
fTrackerMessenger = *messenger;
float height;
BMenu* menu;
BMenu* subMenu;
BMenuItem* item;
BMessage* msg;
BFile file(ref, B_READ_ONLY);
if (ref) {
fRef = new entry_ref(*ref);
fIncoming = true;
} else
fIncoming = false;
fAutoMarkRead = fApp->AutoMarkRead();
BRect r(0, 0, RIGHT_BOUNDARY, 15);
fMenuBar = new BMenuBar(r, "");
// File Menu
menu = new BMenu(B_TRANSLATE("File"));
msg = new BMessage(M_NEW);
msg->AddInt32("type", M_NEW);
menu->AddItem(item = new BMenuItem(B_TRANSLATE("New mail message"),
msg, 'N'));
item->SetTarget(be_app);
// Cheap hack - only show the drafts menu when composing messages. Insert
// a "true || " in the following IF statement if you want the old BeMail
// behaviour. The difference is that without live draft menu updating you
// can open around 100 e-mails (the BeOS maximum number of open files)
// rather than merely around 20, since each open draft-monitoring query
// sucks up one file handle per mounted BFS disk volume. Plus mail file
// opening speed is noticably improved! ToDo: change this to populate the
// Draft menu with the file names on demand - when the user clicks on it;
// don't need a live query since the menu isn't staying up for more than a
// few seconds.
if (!fIncoming) {
QueryMenu *queryMenu;
queryMenu = new QueryMenu(B_TRANSLATE("Open draft"), false);
queryMenu->SetTargetForItems(be_app);
queryMenu->SetPredicate("MAIL:draft==1");
menu->AddItem(queryMenu);
}
if (!fIncoming || resending) {
menu->AddItem(fSendLater = new BMenuItem(B_TRANSLATE("Save as draft"),
new BMessage(M_SAVE_AS_DRAFT), 'S'));
}
if (!resending && fIncoming) {
menu->AddSeparatorItem();
subMenu = new BMenu(B_TRANSLATE("Close and "));
read_flags flag;
read_read_attr(file, flag);
if (flag == B_UNREAD) {
subMenu->AddItem(item = new BMenuItem(
B_TRANSLATE_COMMENT("Leave as 'New'",
"Do not translate New - this is non-localizable e-mail status"),
new BMessage(kMsgQuitAndKeepAllStatus), 'W', B_SHIFT_KEY));
} else {
BString status;
file.ReadAttrString(B_MAIL_ATTR_STATUS, &status);
BString label;
if (status.Length() > 0)
label.SetToFormat(B_TRANSLATE("Leave as '%s'"),
status.String());
else
label = B_TRANSLATE("Leave same");
subMenu->AddItem(item = new BMenuItem(label.String(),
new BMessage(B_QUIT_REQUESTED), 'W'));
AddShortcut('W', B_COMMAND_KEY | B_SHIFT_KEY,
new BMessage(kMsgQuitAndKeepAllStatus));
}
subMenu->AddItem(new BMenuItem(B_TRANSLATE("Move to trash"),
new BMessage(M_DELETE), 'T', B_CONTROL_KEY));
AddShortcut('T', B_SHIFT_KEY | B_COMMAND_KEY,
new BMessage(M_DELETE_NEXT));
subMenu->AddSeparatorItem();
subMenu->AddItem(new BMenuItem(B_TRANSLATE("Set to Saved"),
new BMessage(M_CLOSE_SAVED), 'W', B_CONTROL_KEY));
if (add_query_menu_items(subMenu, INDEX_STATUS, M_STATUS,
B_TRANSLATE("Set to %s")) > 0)
subMenu->AddSeparatorItem();
subMenu->AddItem(new BMenuItem(B_TRANSLATE("Set to" B_UTF8_ELLIPSIS),
new BMessage(M_CLOSE_CUSTOM)));
#if 0
subMenu->AddItem(new BMenuItem(new TMenu(
B_TRANSLATE("Set to" B_UTF8_ELLIPSIS), INDEX_STATUS, M_STATUS,
false, false),
new BMessage(M_CLOSE_CUSTOM)));
#endif
menu->AddItem(subMenu);
fLeaveStatusMenu = subMenu;
} else {
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(B_TRANSLATE("Close"),
new BMessage(B_CLOSE_REQUESTED), 'W'));
}
menu->AddSeparatorItem();
menu->AddItem(fPrint = new BMenuItem(
B_TRANSLATE("Page setup" B_UTF8_ELLIPSIS),
new BMessage(M_PRINT_SETUP)));
menu->AddItem(fPrint = new BMenuItem(
B_TRANSLATE("Print" B_UTF8_ELLIPSIS),
new BMessage(M_PRINT), 'P'));
fMenuBar->AddItem(menu);
menu->AddSeparatorItem();
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Quit"),
new BMessage(B_QUIT_REQUESTED), 'Q'));
item->SetTarget(be_app);
// Edit Menu
menu = new BMenu(B_TRANSLATE("Edit"));
menu->AddItem(fUndo = new BMenuItem(B_TRANSLATE("Undo"),
new BMessage(B_UNDO), 'Z', 0));
fUndo->SetTarget(NULL, this);
menu->AddItem(fRedo = new BMenuItem(B_TRANSLATE("Redo"),
new BMessage(M_REDO), 'Z', B_SHIFT_KEY));
fRedo->SetTarget(NULL, this);
menu->AddSeparatorItem();
menu->AddItem(fCut = new BMenuItem(B_TRANSLATE("Cut"),
new BMessage(B_CUT), 'X'));
fCut->SetTarget(NULL, this);
menu->AddItem(fCopy = new BMenuItem(B_TRANSLATE("Copy"),
new BMessage(B_COPY), 'C'));
fCopy->SetTarget(NULL, this);
menu->AddItem(fPaste = new BMenuItem(B_TRANSLATE("Paste"),
new BMessage(B_PASTE),
'V'));
fPaste->SetTarget(NULL, this);
menu->AddSeparatorItem();
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Select all"),
new BMessage(M_SELECT), 'A'));
menu->AddSeparatorItem();
item->SetTarget(NULL, this);
menu->AddItem(new BMenuItem(B_TRANSLATE("Find" B_UTF8_ELLIPSIS),
new BMessage(M_FIND), 'F'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Find again"),
new BMessage(M_FIND_AGAIN), 'G'));
if (!fIncoming) {
menu->AddSeparatorItem();
menu->AddItem(fQuote =new BMenuItem(B_TRANSLATE("Quote"),
new BMessage(M_QUOTE), B_RIGHT_ARROW));
menu->AddItem(fRemoveQuote = new BMenuItem(B_TRANSLATE("Remove quote"),
new BMessage(M_REMOVE_QUOTE), B_LEFT_ARROW));
menu->AddSeparatorItem();
fSpelling = new BMenuItem(B_TRANSLATE("Check spelling"),
new BMessage(M_CHECK_SPELLING), ';');
menu->AddItem(fSpelling);
if (fApp->StartWithSpellCheckOn())
PostMessage (M_CHECK_SPELLING);
}
menu->AddSeparatorItem();
menu->AddItem(item = new BMenuItem(
B_TRANSLATE("Settings" B_UTF8_ELLIPSIS),
new BMessage(M_PREFS),','));
item->SetTarget(be_app);
fMenuBar->AddItem(menu);
menu->AddItem(item = new BMenuItem(
B_TRANSLATE("Accounts" B_UTF8_ELLIPSIS),
new BMessage(M_ACCOUNTS),'-'));
item->SetTarget(be_app);
// View Menu
if (!resending && fIncoming) {
menu = new BMenu(B_TRANSLATE("View"));
menu->AddItem(fHeader = new BMenuItem(B_TRANSLATE("Show header"),
new BMessage(M_HEADER), 'H'));
menu->AddItem(fRaw = new BMenuItem(B_TRANSLATE("Show raw message"),
new BMessage(M_RAW)));
fMenuBar->AddItem(menu);
}
// Message Menu
menu = new BMenu(B_TRANSLATE("Message"));
if (!resending && fIncoming) {
BMenuItem *menuItem;
menu->AddItem(new BMenuItem(B_TRANSLATE("Reply"),
new BMessage(M_REPLY),'R'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Reply to sender"),
new BMessage(M_REPLY_TO_SENDER),'R',B_OPTION_KEY));
menu->AddItem(new BMenuItem(B_TRANSLATE("Reply to all"),
new BMessage(M_REPLY_ALL), 'R', B_SHIFT_KEY));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(B_TRANSLATE("Forward"),
new BMessage(M_FORWARD), 'J'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Forward without attachments"),
new BMessage(M_FORWARD_WITHOUT_ATTACHMENTS)));
menu->AddItem(menuItem = new BMenuItem(B_TRANSLATE("Resend"),
new BMessage(M_RESEND)));
menu->AddItem(menuItem = new BMenuItem(B_TRANSLATE("Copy to new"),
new BMessage(M_COPY_TO_NEW), 'D'));
menu->AddSeparatorItem();
fDeleteNext = new BMenuItem(B_TRANSLATE("Move to trash"),
new BMessage(M_DELETE_NEXT), 'T');
menu->AddItem(fDeleteNext);
menu->AddSeparatorItem();
fPrevMsg = new BMenuItem(B_TRANSLATE("Previous message"),
new BMessage(M_PREVMSG), B_UP_ARROW);
menu->AddItem(fPrevMsg);
fNextMsg = new BMenuItem(B_TRANSLATE("Next message"),
new BMessage(M_NEXTMSG), B_DOWN_ARROW);
menu->AddItem(fNextMsg);
menu->AddSeparatorItem();
fSaveAddrMenu = subMenu = new BMenu(B_TRANSLATE("Save address"));
menu->AddItem(subMenu);
fMenuBar->AddItem(menu);
// Spam Menu
if (fApp->ShowSpamGUI()) {
menu = new BMenu("Spam filtering");
menu->AddItem(new BMenuItem("Mark as spam and move to trash",
new BMessage(M_TRAIN_SPAM_AND_DELETE), 'K'));
menu->AddItem(new BMenuItem("Mark as spam",
new BMessage(M_TRAIN_SPAM), 'K', B_OPTION_KEY));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Unmark this message",
new BMessage(M_UNTRAIN)));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Mark as genuine",
new BMessage(M_TRAIN_GENUINE), 'K', B_SHIFT_KEY));
fMenuBar->AddItem(menu);
}
} else {
menu->AddItem(fSendNow = new BMenuItem(B_TRANSLATE("Send message"),
new BMessage(M_SEND_NOW), 'M'));
if (!fIncoming) {
menu->AddSeparatorItem();
fSignature = new TMenu(B_TRANSLATE("Add signature"),
INDEX_SIGNATURE, M_SIGNATURE);
menu->AddItem(new BMenuItem(fSignature));
menu->AddItem(item = new BMenuItem(
B_TRANSLATE("Edit signatures" B_UTF8_ELLIPSIS),
new BMessage(M_EDIT_SIGNATURE)));
item->SetTarget(be_app);
menu->AddSeparatorItem();
menu->AddItem(fAdd = new BMenuItem(
B_TRANSLATE("Add enclosure" B_UTF8_ELLIPSIS),
new BMessage(M_ADD), 'E'));
menu->AddItem(fRemove = new BMenuItem(
B_TRANSLATE("Remove enclosure"),
new BMessage(M_REMOVE), 'T'));
}
fMenuBar->AddItem(menu);
}
// Queries Menu
fQueryMenu = new BMenu(B_TRANSLATE("Queries"));
fMenuBar->AddItem(fQueryMenu);
_RebuildQueryMenu(true);
// Menu Bar
AddChild(fMenuBar);
height = fMenuBar->Bounds().bottom + 1;
// Button Bar
float bbwidth = 0, bbheight = 0;
bool showButtonBar = fApp->ShowButtonBar();
if (showButtonBar) {
BuildButtonBar();
fButtonBar->ShowLabels(showButtonBar);
fButtonBar->Arrange(true);
fButtonBar->GetPreferredSize(&bbwidth, &bbheight);
fButtonBar->ResizeTo(Bounds().right, bbheight);
fButtonBar->MoveTo(0, height);
fButtonBar->Show();
} else
fButtonBar = NULL;
r.top = r.bottom = height + bbheight + 1;
fHeaderView = new THeaderView (r, rect, fIncoming, resending,
(resending || !fIncoming)
? fApp->MailCharacterSet()
// Use preferences setting for composing mail.
: B_MAIL_NULL_CONVERSION,
// Default is automatic selection for reading mail.
fApp->DefaultAccount());
r = Frame();
r.OffsetTo(0, 0);
r.top = fHeaderView->Frame().bottom - 1;
fContentView = new TContentView(r, fIncoming, const_cast<BFont *>(font),
false, fApp->ColoredQuotes());
// TContentView needs to be properly const, for now cast away constness
AddChild(fHeaderView);
if (fEnclosuresView)
AddChild(fEnclosuresView);
AddChild(fContentView);
if (to)
fHeaderView->fTo->SetText(to);
AddShortcut('n', B_COMMAND_KEY, new BMessage(M_NEW));
// If auto-signature, add signature to the text here.
BString signature = fApp->Signature();
if (!fIncoming && strcmp(signature.String(), B_TRANSLATE("None")) != 0) {
if (strcmp(signature.String(), B_TRANSLATE("Random")) == 0)
PostMessage(M_RANDOM_SIG);
else {
// Create a query to find this signature
BVolume volume;
BVolumeRoster().GetBootVolume(&volume);
BQuery query;
query.SetVolume(&volume);
query.PushAttr(INDEX_SIGNATURE);
query.PushString(signature.String());
query.PushOp(B_EQ);
query.Fetch();
// If we find the named query, add it to the text.
BEntry entry;
if (query.GetNextEntry(&entry) == B_NO_ERROR) {
BFile file;
file.SetTo(&entry, O_RDWR);
if (file.InitCheck() == B_NO_ERROR) {
entry_ref ref;
entry.GetRef(&ref);
BMessage msg(M_SIGNATURE);
msg.AddRef("ref", &ref);
PostMessage(&msg);
}
} else {
char tempString [2048];
query.GetPredicate (tempString, sizeof (tempString));
printf ("Query failed, was looking for: %s\n", tempString);
}
}
}
OpenMessage(ref, fHeaderView->fCharacterSetUserSees);
_UpdateSizeLimits();
AddShortcut('q', B_SHIFT_KEY, new BMessage(kMsgQuitAndKeepAllStatus));
}
void
TMailWindow::BuildButtonBar()
{
ButtonBar *bbar;
bbar = new ButtonBar(BRect(0, 0, 100, 100), "ButtonBar", 2, 3, 0, 1, 10,
2);
bbar->AddButton(B_TRANSLATE("New"), 28, new BMessage(M_NEW));
bbar->AddDivider(5);
fButtonBar = bbar;
if (fResending) {
fSendButton = bbar->AddButton(B_TRANSLATE("Send"), 8,
new BMessage(M_SEND_NOW));
bbar->AddDivider(5);
} else if (!fIncoming) {
fSendButton = bbar->AddButton(B_TRANSLATE("Send"), 8,
new BMessage(M_SEND_NOW));
fSendButton->SetEnabled(false);
fSigButton = bbar->AddButton(B_TRANSLATE("Signature"), 4,
new BMessage(M_SIG_MENU));
fSigButton->InvokeOnButton(B_SECONDARY_MOUSE_BUTTON);
fSaveButton = bbar->AddButton(B_TRANSLATE("Save"), 44,
new BMessage(M_SAVE_AS_DRAFT));
fSaveButton->SetEnabled(false);
fPrintButton = bbar->AddButton(B_TRANSLATE("Print"), 16,
new BMessage(M_PRINT));
fPrintButton->SetEnabled(false);
bbar->AddButton(B_TRANSLATE("Trash"), 0, new BMessage(M_DELETE));
bbar->AddDivider(5);
} else {
BmapButton *button = bbar->AddButton(B_TRANSLATE("Reply"), 12,
new BMessage(M_REPLY));
button->InvokeOnButton(B_SECONDARY_MOUSE_BUTTON);
button = bbar->AddButton(B_TRANSLATE("Forward"), 40,
new BMessage(M_FORWARD));
button->InvokeOnButton(B_SECONDARY_MOUSE_BUTTON);
fPrintButton = bbar->AddButton(B_TRANSLATE("Print"), 16,
new BMessage(M_PRINT));
bbar->AddButton(B_TRANSLATE("Trash"), 0, new BMessage(M_DELETE_NEXT));
if (fApp->ShowSpamGUI()) {
button = bbar->AddButton("Spam", 48, new BMessage(M_SPAM_BUTTON));
button->InvokeOnButton(B_SECONDARY_MOUSE_BUTTON);
}
bbar->AddDivider(5);
fNextButton = bbar->AddButton(B_TRANSLATE("Next"), 24,
new BMessage(M_NEXTMSG));
bbar->AddButton(B_TRANSLATE("Previous"), 20, new BMessage(M_PREVMSG));
if (!fAutoMarkRead)
_AddReadButton();
}
bbar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
bbar->Hide();
AddChild(bbar);
}
void
TMailWindow::UpdateViews()
{
float bbwidth = 0, bbheight = 0;
float nextY = fMenuBar->Frame().bottom + 1;
uint8 showButtonBar = fApp->ShowButtonBar();
// Show/Hide Button Bar
if (showButtonBar) {
// Create the Button Bar if needed
if (!fButtonBar)
BuildButtonBar();
fButtonBar->ShowLabels(showButtonBar == 1);
fButtonBar->Arrange(true);
// True for all buttons same size, false to just fit
fButtonBar->GetPreferredSize(&bbwidth, &bbheight);
fButtonBar->ResizeTo(Bounds().right, bbheight);
fButtonBar->MoveTo(0, nextY);
nextY += bbheight + 1;
if (fButtonBar->IsHidden())
fButtonBar->Show();
else
fButtonBar->Invalidate();
} else if (fButtonBar && !fButtonBar->IsHidden())
fButtonBar->Hide();
// Arange other views to match
fHeaderView->MoveTo(0, nextY);
nextY = fHeaderView->Frame().bottom;
if (fEnclosuresView) {
fEnclosuresView->MoveTo(0, nextY);
nextY = fEnclosuresView->Frame().bottom + 1;
}
BRect bounds(Bounds());
fContentView->MoveTo(0, nextY - 1);
fContentView->ResizeTo(bounds.right - bounds.left,
bounds.bottom - nextY + 1);
_UpdateSizeLimits();
}
void
TMailWindow::UpdatePreferences()
{
fAutoMarkRead = fApp->AutoMarkRead();
_UpdateReadButton();
}
TMailWindow::~TMailWindow()
{
fApp->SetLastWindowFrame(Frame());
delete fMail;
delete fPanel;
delete fOriginatingWindow;
delete fRef;
BAutolock locker(sWindowListLock);
sWindowList.RemoveItem(this);
}
status_t
TMailWindow::GetMailNodeRef(node_ref &nodeRef) const
{
if (fRef == NULL)
return B_ERROR;
BNode node(fRef);
return node.GetNodeRef(&nodeRef);
}
bool
TMailWindow::GetTrackerWindowFile(entry_ref *ref, bool next) const
{
// Position was already saved
if (next && fNextTrackerPositionSaved) {
*ref = fNextRef;
return true;
}
if (!next && fPrevTrackerPositionSaved) {
*ref = fPrevRef;
return true;
}
if (!fTrackerMessenger.IsValid())
return false;
// Ask the tracker what the next/prev file in the window is.
// Continue asking for the next reference until a valid
// email file is found (ignoring other types).
entry_ref nextRef = *ref;
bool foundRef = false;
while (!foundRef) {
BMessage request(B_GET_PROPERTY);
BMessage spc;
if (next)
spc.what = 'snxt';
else
spc.what = 'sprv';
spc.AddString("property", "Entry");
spc.AddRef("data", &nextRef);
request.AddSpecifier(&spc);
BMessage reply;
if (fTrackerMessenger.SendMessage(&request, &reply) != B_OK)
return false;
if (reply.FindRef("result", &nextRef) != B_OK)
return false;
char fileType[256];
BNode node(&nextRef);
if (node.InitCheck() != B_OK)
return false;
if (BNodeInfo(&node).GetType(fileType) != B_OK)
return false;
if (strcasecmp(fileType, B_MAIL_TYPE) == 0
|| strcasecmp(fileType, B_PARTIAL_MAIL_TYPE) == 0)
foundRef = true;
}
*ref = nextRef;
return foundRef;
}
void
TMailWindow::SaveTrackerPosition(entry_ref *ref)
{
// if only one of them is saved, we're not going to do it again
if (fNextTrackerPositionSaved || fPrevTrackerPositionSaved)
return;
fNextRef = fPrevRef = *ref;
fNextTrackerPositionSaved = GetTrackerWindowFile(&fNextRef, true);
fPrevTrackerPositionSaved = GetTrackerWindowFile(&fPrevRef, false);
}
void
TMailWindow::SetOriginatingWindow(BWindow *window)
{
delete fOriginatingWindow;
fOriginatingWindow = new BMessenger(window);
}
void
TMailWindow::SetTrackerSelectionToCurrent()
{
BMessage setSelection(B_SET_PROPERTY);
setSelection.AddSpecifier("Selection");
setSelection.AddRef("data", fRef);
fTrackerMessenger.SendMessage(&setSelection);
}
void
TMailWindow::PreserveReadingPos(bool save)
{
BScrollBar *scroll = fContentView->fTextView->ScrollBar(B_VERTICAL);
if (scroll == NULL || fRef == NULL)
return;
BNode node(fRef);
float pos = scroll->Value();
const char* name = "MAIL:read_pos";
if (save) {
node.WriteAttr(name, B_FLOAT_TYPE, 0, &pos, sizeof(pos));
return;
}
if (node.ReadAttr(name, B_FLOAT_TYPE, 0, &pos, sizeof(pos)) == sizeof(pos)) {
Lock();
scroll->SetValue(pos);
Unlock();
}
}
void
TMailWindow::MarkMessageRead(entry_ref* message, read_flags flag)
{
BNode node(message);
status_t status = node.InitCheck();
if (status != B_OK)
return;
int32 account;
if (node.ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0, &account,
sizeof(account)) < 0)
account = -1;
// don't wait for the server write the attribute directly
write_read_attr(node, flag);
// preserve the read position in the node attribute
PreserveReadingPos(true);
BMailDaemon::MarkAsRead(account, *message, flag);
}
void
TMailWindow::FrameResized(float width, float height)
{
fContentView->FrameResized(width, height);
}
void
TMailWindow::MenusBeginning()
{
bool enable;
int32 finish = 0;
int32 start = 0;
BTextView *textView;
if (!fIncoming) {
bool gotToField = fHeaderView->fTo->Text()[0] != 0;
bool gotCcField = fHeaderView->fCc->Text()[0] != 0;
bool gotBccField = fHeaderView->fBcc->Text()[0] != 0;
bool gotSubjectField = fHeaderView->fSubject->Text()[0] != 0;
bool gotText = fContentView->fTextView->Text()[0] != 0;
fSendNow->SetEnabled(gotToField || gotBccField);
fSendLater->SetEnabled(fChanged && (gotToField || gotCcField
|| gotBccField || gotSubjectField || gotText));
be_clipboard->Lock();
fPaste->SetEnabled(be_clipboard->Data()->HasData("text/plain",
B_MIME_TYPE)
&& (fEnclosuresView == NULL || !fEnclosuresView->fList->IsFocus()));
be_clipboard->Unlock();
fQuote->SetEnabled(false);
fRemoveQuote->SetEnabled(false);
fAdd->SetEnabled(true);
fRemove->SetEnabled(fEnclosuresView != NULL
&& fEnclosuresView->fList->CurrentSelection() >= 0);
} else {
if (fResending) {
enable = strlen(fHeaderView->fTo->Text());
fSendNow->SetEnabled(enable);
// fSendLater->SetEnabled(enable);
if (fHeaderView->fTo->HasFocus()) {
textView = fHeaderView->fTo->TextView();
textView->GetSelection(&start, &finish);
fCut->SetEnabled(start != finish);
be_clipboard->Lock();
fPaste->SetEnabled(be_clipboard->Data()->HasData(
"text/plain", B_MIME_TYPE));
be_clipboard->Unlock();
} else {
fCut->SetEnabled(false);
fPaste->SetEnabled(false);
}
} else {
fCut->SetEnabled(false);
fPaste->SetEnabled(false);
if (!fTrackerMessenger.IsValid()) {
fNextMsg->SetEnabled(false);
fPrevMsg->SetEnabled(false);
}
}
}
fPrint->SetEnabled(fContentView->fTextView->TextLength());
textView = dynamic_cast<BTextView *>(CurrentFocus());
if (textView != NULL
&& dynamic_cast<TTextControl *>(textView->Parent()) != NULL) {
// one of To:, Subject:, Account:, Cc:, Bcc:
textView->GetSelection(&start, &finish);
} else if (fContentView->fTextView->IsFocus()) {
fContentView->fTextView->GetSelection(&start, &finish);
if (!fIncoming) {
fQuote->SetEnabled(true);
fRemoveQuote->SetEnabled(true);
}
}
fCopy->SetEnabled(start != finish);
if (!fIncoming)
fCut->SetEnabled(start != finish);
// Undo stuff
bool isRedo = false;
undo_state undoState = B_UNDO_UNAVAILABLE;
BTextView *focusTextView = dynamic_cast<BTextView *>(CurrentFocus());
if (focusTextView != NULL)
undoState = focusTextView->UndoState(&isRedo);
// fUndo->SetLabel((isRedo)
// ? kRedoStrings[undoState] : kUndoStrings[undoState]);
fUndo->SetEnabled(undoState != B_UNDO_UNAVAILABLE);
if (fLeaveStatusMenu != NULL && fRef != NULL) {
BFile file(fRef, B_READ_ONLY);
BString status;
file.ReadAttrString(B_MAIL_ATTR_STATUS, &status);
BMenuItem* LeaveStatus = fLeaveStatusMenu->FindItem(B_QUIT_REQUESTED);
if (LeaveStatus == NULL)
LeaveStatus = fLeaveStatusMenu->FindItem(kMsgQuitAndKeepAllStatus);
if (LeaveStatus != NULL && status.Length() > 0) {
BString label;
label.SetToFormat(B_TRANSLATE("Leave as '%s'"), status.String());
LeaveStatus->SetLabel(label.String());
}
}
}
void
TMailWindow::MessageReceived(BMessage *msg)
{
bool wasReadMsg = false;
switch (msg->what) {
case kMsgBodyFetched:
{
status_t status = msg->FindInt32("status");
if (status != B_OK) {
PostMessage(B_QUIT_REQUESTED);
break;
}
entry_ref ref;
if (msg->FindRef("ref", &ref) != B_OK)
break;
if (ref != *fRef)
break;
// reload the current message
OpenMessage(&ref, fHeaderView->fCharacterSetUserSees);
break;
}
case FIELD_CHANGED:
{
int32 prevState = fFieldState;
int32 fieldMask = msg->FindInt32("bitmask");
void *source;
if (msg->FindPointer("source", &source) == B_OK) {
int32 length;
if (fieldMask == FIELD_BODY)
length = ((TTextView *)source)->TextLength();
else
length = ((BComboBox *)source)->TextView()->TextLength();
if (length)
fFieldState |= fieldMask;
else
fFieldState &= ~fieldMask;
}
// Has anything changed?
if (prevState != fFieldState || !fChanged) {
// Change Buttons to reflect this
if (fSaveButton)
fSaveButton->SetEnabled(fFieldState);