xref: /haiku/src/apps/mail/MailSupport.cpp (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2001, Be Incorporated. All rights reserved.
7 
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:
14 
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.
17 
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.
24 
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.
28 
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.
33 */
34 
35 
36 #include "MailSupport.h"
37 
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>
45 
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>
57 
58 #include <fs_index.h>
59 #include <fs_info.h>
60 
61 #include <MailMessage.h>
62 #include <MailSettings.h>
63 #include <MailDaemon.h>
64 #include <mail_util.h>
65 #include <MDRLanguage.h>
66 
67 #include <CharacterSetRoster.h>
68 
69 #include "Utilities.h"
70 
71 
72 using namespace BPrivate ;
73 
74 #ifdef HAIKU_TARGET_PLATFORM_BEOS
75 	#include <netdb.h>
76 #endif
77 
78 
79 #include "Words.h"
80 
81 // global variables
82 Words*	gWords[MAX_DICTIONARIES];
83 Words*	gExactWords[MAX_DICTIONARIES];
84 
85 int32	gUserDict;
86 BFile*	gUserDictFile;
87 int32 	gDictCount = 0;
88 
89 // int32			level = L_BEGINNER;
90 
91 const char* kSpamServerSignature = "application/x-vnd.agmsmith.spamdbm";
92 const char* kDraftPath = "mail/draft";
93 const char* kDraftType = "text/x-vnd.Be-MailDraft";
94 const char* kMailFolder = "mail";
95 const char* kMailboxFolder = "mail/mailbox";
96 
97 
98 int32
99 header_len(BFile *file)
100 {
101 	char	*buffer;
102 	int32	length;
103 	int32	result = 0;
104 	off_t	size;
105 
106 	if (file->ReadAttr(B_MAIL_ATTR_HEADER, B_INT32_TYPE, 0, &result,
107 		sizeof(int32)) != sizeof(int32)) {
108 		file->GetSize(&size);
109 		buffer = (char *)malloc(size);
110 		if (buffer) {
111 			file->Seek(0, 0);
112 			if (file->Read(buffer, size) == size) {
113 				while ((length = linelen(buffer + result, size - result, true)) > 2)
114 					result += length;
115 
116 				result += length;
117 			}
118 			free(buffer);
119 			file->WriteAttr(B_MAIL_ATTR_HEADER, B_INT32_TYPE, 0, &result, sizeof(int32));
120 		}
121 	}
122 	return result;
123 }
124 
125 
126 int32
127 add_query_menu_items(BMenu* menu, const char* attribute, uint32 what,
128 	const char* format, bool popup)
129 {
130 	BVolume	volume;
131 	BVolumeRoster().GetBootVolume(&volume);
132 
133 	BQuery query;
134 	query.SetVolume(&volume);
135 	query.PushAttr(attribute);
136 	query.PushString("*");
137 	query.PushOp(B_EQ);
138 	query.Fetch();
139 
140 	int32 index = 0;
141 	BEntry entry;
142 	while (query.GetNextEntry(&entry) == B_OK) {
143 		BFile file(&entry, B_READ_ONLY);
144 		if (file.InitCheck() == B_OK) {
145 			BMessage* message = new BMessage(what);
146 
147 			entry_ref ref;
148 			entry.GetRef(&ref);
149 			message->AddRef("ref", &ref);
150 
151 			BString value;
152 			if (file.ReadAttrString(attribute, &value) < B_OK)
153 				continue;
154 
155 			message->AddString("attribute", value.String());
156 
157 			char name[256];
158 			if (format != NULL)
159 				snprintf(name, sizeof(name), format, value.String());
160 			else
161 				strlcpy(name, value.String(), sizeof(name));
162 
163 			if (index < 9 && !popup)
164 				menu->AddItem(new BMenuItem(name, message, '1' + index));
165 			else
166 				menu->AddItem(new BMenuItem(name, message));
167 			index++;
168 		}
169 	}
170 
171 	return index;
172 }
173 
174