1 #include "smapimsg.h"
2
3
smapiMsg(HAREA newarea,dword newmsgnum)4 smapiMsg::smapiMsg(HAREA newarea, dword newmsgnum)
5 {
6 debug("smapiMsg::smapiMsg");
7 areaheader = newarea;
8 msgnum = newmsgnum;
9 if (msgnum != 0) {
10 // not a new msg
11 msgheader = MsgOpenMsg(areaheader, MOPEN_READ, msgnum);
12 if (msgheader != 0) {
13 MsgReadMsg(msgheader, &extendedmsginfo, 0, 0, NULL, 0, NULL);
14 addr = new address();
15
16 // parse the attributes
17 attr = new msgattributes();
18 attr->setMsgPrivate((extendedmsginfo.attr & MSGPRIVATE) == MSGPRIVATE);
19 attr->setMsgLocal((extendedmsginfo.attr & MSGLOCAL) == MSGLOCAL);
20 attr->setMsgCrash((extendedmsginfo.attr & MSGCRASH) == MSGCRASH);
21 attr->setMsgHold((extendedmsginfo.attr & MSGHOLD) == MSGHOLD);
22 attr->setMsgDirect((extendedmsginfo.attr & MSGCRASH & MSGHOLD) == MSGCRASH & MSGHOLD);
23 attr->setMsgRead((extendedmsginfo.attr & MSGREAD) == MSGREAD);
24 attr->setMsgSent((extendedmsginfo.attr & MSGSENT) == MSGSENT);
25 attr->setMsgScanned((extendedmsginfo.attr & MSGSCANNED) == MSGSCANNED);
26 attr->setMsgFile((extendedmsginfo.attr & MSGFILE) == MSGFILE);
27 attr->setMsgFrq((extendedmsginfo.attr & MSGFRQ) == MSGFRQ);
28 attr->setMsgUrq((extendedmsginfo.attr & MSGURQ) == MSGURQ);
29 attr->setMsgKill((extendedmsginfo.attr & MSGKILL) == MSGKILL);
30 attr->setMsgRrq((extendedmsginfo.attr & MSGRRQ) == MSGRRQ);
31 attr->setMsgCpt((extendedmsginfo.attr & MSGCPT) == MSGCPT);
32 attr->setMsgArq((extendedmsginfo.attr & MSGARQ) == MSGARQ);
33 attr->setMsgFwd((extendedmsginfo.attr & MSGFWD) == MSGFWD);
34 attr->setMsgOrphan((extendedmsginfo.attr & MSGORPHAN) == MSGORPHAN);
35 // attr->setMsgUid((xmsg.attr & MSGUID) == MSGUID);
36 MsgCloseMsg(msgheader);
37 } else {
38 fatal("smapiMsg::smapiMsg(HAREA newarea, dword newmsgnum)\nerror opening a msg. ErrorNr: %d", msgapierr);
39 }
40 } else {
41 // a new message
42 debug("new msg - num: %d", msgnum);
43 msgheader = MsgOpenMsg(newarea, MOPEN_CREATE, msgnum);
44 debug("new msg - num: %d", msgnum);
45 // *** make it appear in the msglist
46 attr = new msgattributes();
47 /// *** initialize with defaults for area
48 addr = new address();
49 MsgCloseMsg(msgheader);
50 }
51 }
52
53
54
~smapiMsg()55 smapiMsg::~smapiMsg()
56 {
57 delete attr;
58 delete addr;
59 }
60
61
62
getCurMsg()63 int smapiMsg::getCurMsg()
64 {
65 return msgnum;
66 }
67
68
69
getFrom()70 QString smapiMsg::getFrom()
71 {
72 QString from;
73 from.sprintf((char *)extendedmsginfo.from);
74 return from;
75 }
76
77
getTo()78 QString smapiMsg::getTo()
79 {
80 QString to;
81 to.sprintf((char *)extendedmsginfo.to);
82 return to;
83 }
84
85
getSubject()86 QString smapiMsg::getSubject()
87 {
88 QString subject;
89 subject.sprintf((char *)extendedmsginfo.subj);
90 return subject;
91 }
92
93
94
getAttr()95 msgattributes *smapiMsg::getAttr()
96 {
97 return attr;
98 }
99
100
101
isUnread()102 bool smapiMsg::isUnread()
103 {
104 return (! attr->isMsgRead());
105 }
106
107
108
109 // normalize, borrowed from msged, with slight modifications
110
normalize(char * s,int stripSoft)111 void normalize(char *s, int stripSoft)
112 {
113 char *tmp = s;
114
115 while (*s)
116 {
117 if (stripSoft && ((unsigned char)*s == 0x8d))
118 {
119 s++;
120 }
121 else if (*s == 0x0a)
122 {
123 s++;
124 }
125 else if (*s == 0x0d) {
126 s++, *tmp++ = '\n';
127 }
128 else
129 {
130 *tmp++ = (char)/*DOROT13*/((int)*s);
131 s++;
132 }
133 }
134 *tmp = '\0';
135 }
136
137
138
getBody()139 QString smapiMsg::getBody()
140 {
141 char *bodycontent;
142 char *ctrlinfo;
143
144 char *pid;
145 char *tid;
146 char *charset;
147
148 debug("smapiMsg::getBody()");
149
150 msgheader = MsgOpenMsg(areaheader, MOPEN_READ, msgnum);
151 if (msgheader != 0) {
152 bodycontent = new char[MsgGetTextLen(msgheader)];
153 ctrlinfo = new char[MsgGetCtrlLen(msgheader)];
154
155 debug("hmsg != null");
156 MsgReadMsg(msgheader, 0L, 0L, MsgGetTextLen(msgheader), bodycontent, MsgGetCtrlLen(msgheader), ctrlinfo);
157
158 // parse the control info
159 debug("PID: %s", GetCtrlToken(ctrlinfo, (byte *) "PID"));
160 // *** store them!
161
162 // find something nicer, when I have time
163 debug("vor normalize");
164 normalize(bodycontent, 0);
165 return (const char *)bodycontent;
166 } else {
167 fatal("Could not open %s", "echo->filename");
168 return 0;
169 }
170 }
171
172
173
setAttr(msgattributes * newattr)174 void smapiMsg::setAttr(msgattributes *newattr)
175 {
176 attr = newattr;
177
178 // *** make attr.toxmsgAttr
179 extendedmsginfo.attr = 0;
180
181 if (attr->isMsgPrivate()) extendedmsginfo.attr = extendedmsginfo.attr | MSGPRIVATE;
182 if (attr->isMsgLocal()) extendedmsginfo.attr = extendedmsginfo.attr | MSGLOCAL;
183 if (attr->isMsgCrash()) extendedmsginfo.attr = extendedmsginfo.attr | MSGCRASH;
184 if (attr->isMsgHold()) extendedmsginfo.attr = extendedmsginfo.attr | MSGHOLD;
185 if (attr->isMsgRead()) extendedmsginfo.attr = extendedmsginfo.attr | MSGREAD;
186 if (attr->isMsgSent()) extendedmsginfo.attr = extendedmsginfo.attr | MSGSENT;
187 if (attr->isMsgScanned()) extendedmsginfo.attr = extendedmsginfo.attr | MSGSCANNED;
188 if (attr->isMsgFile()) extendedmsginfo.attr = extendedmsginfo.attr | MSGFILE;
189 if (attr->isMsgFrq()) extendedmsginfo.attr = extendedmsginfo.attr | MSGFRQ;
190 if (attr->isMsgUrq()) extendedmsginfo.attr = extendedmsginfo.attr | MSGURQ;
191 if (attr->isMsgKill()) extendedmsginfo.attr = extendedmsginfo.attr | MSGKILL;
192 if (attr->isMsgRrq()) extendedmsginfo.attr = extendedmsginfo.attr | MSGRRQ;
193 if (attr->isMsgCpt()) extendedmsginfo.attr = extendedmsginfo.attr | MSGCPT;
194 if (attr->isMsgArq()) extendedmsginfo.attr = extendedmsginfo.attr | MSGARQ;
195 if (attr->isMsgFwd()) extendedmsginfo.attr = extendedmsginfo.attr | MSGFWD;
196 if (attr->isMsgOrphan()) extendedmsginfo.attr = extendedmsginfo.attr | MSGORPHAN;
197 }
198
199
200
setRead()201 void smapiMsg::setRead()
202 {
203 attr->setMsgRead(true);
204 }
205
206
207
setKludges(char * newkludges)208 void smapiMsg::setKludges(char* newkludges)
209 {
210 debug("void smapiMsg::setKludges(char* newkludges)");
211 // kludges = new char[sizeof(newkludges)];
212 char* kludges = (char*) malloc(255);
213 strcpy(kludges, newkludges);
214 debug("kludges: %s", kludges);
215 debug("size of kludges: %d", sizeof(kludges));
216 }
217
218
219
setFrom(QString newfrom)220 void smapiMsg::setFrom(QString newfrom)
221 {
222 strcpy((char *)extendedmsginfo.from, newfrom);
223 }
224
225
226
setTo(QString newto)227 void smapiMsg::setTo(QString newto)
228 {
229 strcpy((char *)extendedmsginfo.to, newto);
230 }
231
232
233
setSubject(QString newsubject)234 void smapiMsg::setSubject(QString newsubject)
235 {
236 strcpy((char *)extendedmsginfo.subj, newsubject);
237 }
238
239
240
setOrigAddr(address * newaddress)241 void smapiMsg::setOrigAddr(address* newaddress)
242 {
243 // *** create address::address2NETADDR
244 addr = newaddress;
245 extendedmsginfo.orig.zone = newaddress->getZone();
246 extendedmsginfo.orig.net = newaddress->getNet();
247 extendedmsginfo.orig.node = newaddress->getNode();
248 extendedmsginfo.orig.point = newaddress->getPoint();
249 }
250
251
252
setDateWritten(QDateTime newdatetime)253 void smapiMsg::setDateWritten(QDateTime newdatetime)
254 {
255 debug("smapiMsg::setDateWritten(QDateTime)");
256 SCOMBO newdt;
257 newdt.msg_st.date.yr = newdatetime.date().year()-1980; // squish starts 1980
258 newdt.msg_st.date.mo = newdatetime.date().month();
259 newdt.msg_st.date.da = newdatetime.date().day();
260 newdt.msg_st.time.hh = newdatetime.time().hour();
261 newdt.msg_st.time.mm = newdatetime.time().minute();
262 newdt.msg_st.time.ss = (int)newdatetime.time().second()/2; // squish is unsharp, only 2 second steps
263
264 extendedmsginfo.date_written = newdt.msg_st;
265 }
266
267
268
setBody(QString newbody)269 void smapiMsg::setBody(QString newbody)
270 {
271 body = new char[sizeof("newbody")];
272 sprintf(body, "newbody");
273 debug("body:%s", body);
274 debug("size of body: %d", strlen(body));
275 }
276
277
278
writeMsg()279 void smapiMsg::writeMsg()
280 {
281 debug("smapiMsg::writeMsg()");
282
283 /* sword MsgWriteMsg(HMSG hmsg, word fAppend, PXMSG msg,
284 byte *text, dword textlen, dword totlen,
285 dword clen, byte *ctxt);
286 */
287 // the kludges
288 char* tmp = (char*) calloc(128, sizeof(char));
289 sprintf(tmp, "\1PID: %s %s\1MSGID: %s",
290 "kfe", "0.1.0", addr->toMsgId);
291
292
293 MsgWriteMsg(msgheader, 0, &extendedmsginfo,
294 (byte*) body, (dword) strlen(body), (unsigned char*) strlen(body),
295 (dword) strlen(tmp), (unsigned char*) tmp);
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