libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / mail / MailSupport.cpp
blob55760a2483f3068d00f869001fd720303f5b6d84
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2001, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 BeMail(TM), Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
36 #include "MailSupport.h"
38 #include <fcntl.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <sys/stat.h>
43 #include <sys/utsname.h>
44 #include <unistd.h>
46 #include <Autolock.h>
47 #include <Clipboard.h>
48 #include <Debug.h>
49 #include <E-mail.h>
50 #include <InterfaceKit.h>
51 #include <Roster.h>
52 #include <Screen.h>
53 #include <StorageKit.h>
54 #include <String.h>
55 #include <TextView.h>
56 #include <UTF8.h>
58 #include <fs_index.h>
59 #include <fs_info.h>
61 #include <MailMessage.h>
62 #include <MailSettings.h>
63 #include <MailDaemon.h>
64 #include <mail_util.h>
66 #include <CharacterSetRoster.h>
68 #include "Utilities.h"
71 using namespace BPrivate ;
73 #include "Words.h"
75 // global variables
76 Words* gWords[MAX_DICTIONARIES];
77 Words* gExactWords[MAX_DICTIONARIES];
79 int32 gUserDict;
80 BFile* gUserDictFile;
81 int32 gDictCount = 0;
83 // int32 level = L_BEGINNER;
85 const char* kSpamServerSignature =
86 "application/x-vnd.agmsmith.spamdbm";
87 const char* kDraftPath = "mail/draft";
88 const char* kDraftType = "text/x-vnd.Be-MailDraft";
89 const char* kMailFolder = "mail";
90 const char* kMailboxSymlink = "Mail/mailbox";
91 // relative to B_USER_SETTINGS_DIRECTORY
94 int32
95 header_len(BFile *file)
97 char *buffer;
98 int32 length;
99 int32 result = 0;
100 off_t size;
102 if (file->ReadAttr(B_MAIL_ATTR_HEADER, B_INT32_TYPE, 0, &result,
103 sizeof(int32)) != sizeof(int32)) {
104 file->GetSize(&size);
105 buffer = (char *)malloc(size);
106 if (buffer) {
107 file->Seek(0, 0);
108 if (file->Read(buffer, size) == size) {
109 while ((length = linelen(buffer + result, size - result, true)) > 2)
110 result += length;
112 result += length;
114 free(buffer);
115 file->WriteAttr(B_MAIL_ATTR_HEADER, B_INT32_TYPE, 0, &result, sizeof(int32));
118 return result;
122 int32
123 add_query_menu_items(BMenu* menu, const char* attribute, uint32 what,
124 const char* format, bool popup)
126 BVolume volume;
127 BVolumeRoster().GetBootVolume(&volume);
129 BQuery query;
130 query.SetVolume(&volume);
131 query.PushAttr(attribute);
132 query.PushString("*");
133 query.PushOp(B_EQ);
134 query.Fetch();
136 int32 index = 0;
137 BEntry entry;
138 while (query.GetNextEntry(&entry) == B_OK) {
139 BFile file(&entry, B_READ_ONLY);
140 if (file.InitCheck() == B_OK) {
141 BMessage* message = new BMessage(what);
143 entry_ref ref;
144 entry.GetRef(&ref);
145 message->AddRef("ref", &ref);
147 BString value;
148 if (file.ReadAttrString(attribute, &value) < B_OK)
149 continue;
151 message->AddString("attribute", value.String());
153 BString name;
154 if (format != NULL)
155 name.SetToFormat(format, value.String());
156 else
157 name = value;
159 if (index < 9 && !popup)
160 menu->AddItem(new BMenuItem(name, message, '1' + index));
161 else
162 menu->AddItem(new BMenuItem(name, message));
163 index++;
167 return index;