TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

397 lines
9.3KB

  1. /***************************************************************************
  2. mapihd.cpp - description
  3. -------------------
  4. begin : Tue Jul 25 2000
  5. copyright : (C) 2000 by Hans Dijkema
  6. email : kmailcvt@hum.org
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "pab_pablib.h"
  17. bool operator < (mapitag_t & a,mapitag_t & b) { return a._order<b._order; }
  18. bool operator > (mapitag_t & a,mapitag_t & b) { return a._order>b._order; }
  19. bool operator == (mapitag_t & a,mapitag_t & b) { return a._order==b._order; }
  20. static word_t
  21. map_givenname[]=
  22. { pr_givenname,
  23. SET_MS_GIVEN_NAME,
  24. 0
  25. },
  26. map_email[]=
  27. { pr_email,
  28. SET_MS_EMAIL,
  29. 0
  30. },
  31. map_firstname[]=
  32. { pr_firstname,
  33. SET_MS_FIRSTNAME,
  34. 0
  35. },
  36. map_lastname[]=
  37. { pr_lastname,
  38. SET_MS_LASTNAME,
  39. 0
  40. },
  41. map_additionalname[]=
  42. { pr_additionalname,
  43. SET_MS_MIDDLENAME,
  44. 0
  45. },
  46. map_title[]=
  47. { pr_title,
  48. SET_MS_TITLE,
  49. 0
  50. },
  51. map_address[]=
  52. { pr_address,
  53. SET_MS_ADDRESS,
  54. 0
  55. },
  56. map_zip[]=
  57. { pr_zip,
  58. SET_MS_ZIP,
  59. 0
  60. },
  61. map_state[]=
  62. { pr_state,
  63. SET_MS_STATE,
  64. 0
  65. },
  66. map_town[]=
  67. { pr_town,
  68. SET_MS_TOWN,
  69. 0
  70. },
  71. map_country[]=
  72. { pr_country,
  73. SET_MS_COUNTRY,
  74. 0
  75. },
  76. map_tel[]=
  77. { pr_tel,
  78. SET_MS_TEL,
  79. 0
  80. },
  81. map_mobile[]=
  82. { pr_mobile,
  83. SET_MS_MOBILE,
  84. 0
  85. },
  86. map_fax[]=
  87. { pr_fax,
  88. SET_MS_FAX,
  89. 0
  90. },
  91. map_job[]=
  92. { pr_job,
  93. HP_OPENMAIL_JOB,
  94. 0
  95. },
  96. map_organization[]=
  97. { pr_organization,
  98. SET_MS_ORGANIZATION,
  99. HP_OPENMAIL_ORGANIZATION,
  100. 0
  101. },
  102. map_department[]=
  103. { pr_department,
  104. SET_MS_DEPARTMENT,
  105. HP_OPENMAIL_DEPARTMENT,
  106. 0
  107. },
  108. map_subdep[]=
  109. { pr_subdep,
  110. HP_OPENMAIL_SUBDEP,
  111. 0
  112. },
  113. map_notes[]=
  114. { pr_notes,
  115. SET_MS_COMMENT,
  116. 0
  117. },
  118. map_notused[]=
  119. { pr_notused,
  120. HP_OPENMAIL_LOCATION_OF_WORK, // location of work
  121. SET_NOT_USED,
  122. 0
  123. };
  124. static word_t *mapi_map[]={ map_givenname, map_email,
  125. map_firstname, map_lastname, map_additionalname,map_title,
  126. map_address, map_town, map_zip, map_state, map_country,
  127. map_tel, map_mobile, map_fax,
  128. map_organization, map_department, map_subdep, map_job,
  129. map_notes,
  130. map_notused,
  131. NULL
  132. };
  133. pabrec_entry mapitag_t::matchTag(void)
  134. {
  135. int i,j;
  136. pabrec_entry e=pr_unknown;
  137. for(i=0;mapi_map[i]!=NULL && e==pr_unknown;i++) {
  138. for(j=1;mapi_map[i][j]!=0 && _tag!=mapi_map[i][j];j++);
  139. if (mapi_map[i][j]!=0) {
  140. e=(pabrec_entry) mapi_map[i][0];
  141. }
  142. }
  143. return e;
  144. }
  145. pabfields_t::pabfields_t(pabrec & R, TQWidget * /*parent*/)
  146. {
  147. // Skip the first two words, because they're always the
  148. // same 000c 0014 ==> 0014 gives us the types, so we
  149. // parse from 0014 till the next offset and order the tags.
  150. int mb,me;
  151. uint i,k;
  152. content_t _tag,_order;
  153. mb=R[1];
  154. me=R[2];
  155. while (mb<me) {
  156. _tag=R.read(mb);mb+=sizeof(_tag);
  157. _order=R.read(mb);mb+=sizeof(_order);
  158. {mapitag_t mt(_tag,_order);
  159. tags[tags.size()]=mt;
  160. context_tags[context_tags.size()]=mt;
  161. }
  162. }
  163. tags.sort();
  164. // get the right entries now
  165. for(i=2,k=0;i<R.N() && k<tags.size();i++,k++) {
  166. if (!isUsed(k)) { i-=1; }
  167. else {pabrec_entry e;
  168. TQString E;
  169. e=isWhat(k);
  170. E=R.getEntry(i);
  171. { TQString s=E;
  172. s=s.stripWhiteSpace();
  173. E=s;
  174. }
  175. /*
  176. { char m[1024];
  177. snprintf(m, sizeof(m), "%d %d %04x %08lx %d %s %d %d",i,k,literal(k),order(k),e,E.latin1(),E[0].latin1(),E.length());
  178. info->addLog(m);
  179. }
  180. */
  181. if (!E.isEmpty()) {
  182. switch (e) {
  183. case pr_givenname: givenName=E;
  184. break;
  185. case pr_email: email=E;
  186. break;
  187. case pr_firstname: firstName=E;
  188. break;
  189. case pr_additionalname: additionalName=E;
  190. break;
  191. case pr_lastname: lastName=E;
  192. break;
  193. case pr_title: title=E;
  194. break;
  195. case pr_address: address=E;
  196. break;
  197. case pr_town: town=E;
  198. break;
  199. case pr_state: state=E;
  200. break;
  201. case pr_zip: zip=E;
  202. break;
  203. case pr_country: country=E;
  204. break;
  205. case pr_organization: organization=E;
  206. break;
  207. case pr_department: department=E;
  208. break;
  209. case pr_subdep: subDep=E;
  210. break;
  211. case pr_job: job=E;
  212. break;
  213. case pr_tel: tel=E;
  214. break;
  215. case pr_fax: fax=E;
  216. break;
  217. case pr_modem: modem=E;
  218. break;
  219. case pr_mobile: mobile=E;
  220. break;
  221. case pr_url: homepage=E;
  222. break;
  223. case pr_talk: talk=E;
  224. break;
  225. case pr_notes: comment=E;
  226. break;
  227. case pr_birthday: birthday=E;
  228. break;
  229. case pr_notused:
  230. break;
  231. default: {/*char m[250];
  232. snprintf(m,sizeof(m),"unknown tag '%x'",literal(k));
  233. info->log(m);*/
  234. }
  235. break;
  236. }
  237. }
  238. }
  239. }
  240. if (!firstName.isEmpty() && !lastName.isEmpty()) {
  241. givenName=lastName+", "+firstName;
  242. }
  243. // Determine if the record is ok.
  244. OK=true;
  245. }
  246. bool pabfields_t::isUsed(int k)
  247. {
  248. return tags[k].isUsed();
  249. }
  250. pabrec_entry pabfields_t::isWhat(int k)
  251. {
  252. return tags[k].matchTag();
  253. }
  254. word_t pabfields_t::literal(int k)
  255. {
  256. return tags[k].literal();
  257. }
  258. content_t pabfields_t::order(int k)
  259. {
  260. return tags[k].order();
  261. }
  262. KABC::Addressee pabfields_t::get() {
  263. KABC::Addressee a;
  264. if (!givenName.isEmpty()) a.setFormattedName(givenName);
  265. if (!email.isEmpty()) a.insertEmail(email);
  266. if (!title.isEmpty()) a.setTitle(title);
  267. if (!firstName.isEmpty()) a.setName(firstName);
  268. if (!additionalName.isEmpty()) a.setAdditionalName(additionalName);
  269. if (!lastName.isEmpty()) a.setFamilyName(lastName);
  270. KABC::Address addr;
  271. if (!address.isEmpty()) addr.setStreet(address);
  272. if (!town.isEmpty()) addr.setLocality(town);
  273. if (!zip.isEmpty()) addr.setPostalCode(zip);
  274. if (!state.isEmpty()) addr.setRegion(state);
  275. if (!country.isEmpty()) addr.setCountry(country);
  276. a.insertAddress(addr);
  277. if (!organization.isEmpty()) a.setOrganization(organization);
  278. if (!department.isEmpty()) a.setRole(department);
  279. // Miss out department, subDep, job
  280. if (!tel.isEmpty()) a.insertPhoneNumber( KABC::PhoneNumber( tel, KABC::PhoneNumber::Voice ) );
  281. if (!fax.isEmpty()) a.insertPhoneNumber( KABC::PhoneNumber( fax, KABC::PhoneNumber::Fax ) );
  282. if (!mobile.isEmpty()) a.insertPhoneNumber( KABC::PhoneNumber( mobile, KABC::PhoneNumber::Cell ) );
  283. if (!modem.isEmpty()) a.insertPhoneNumber( KABC::PhoneNumber( modem, KABC::PhoneNumber::Modem ) );
  284. if (!homepage.isEmpty()) a.setUrl(KURL( homepage ));
  285. // Miss out talk
  286. if (!comment.isEmpty()) a.setNote(comment);
  287. // Miss out birthday
  288. return a;
  289. }
  290. /* class pabrec {
  291. private:
  292. char entry[1024];
  293. byte *_mem;
  294. word_t *_N;
  295. word_t *_w;
  296. public:
  297. pabrec(pab *); // expects record the begin at reading point (ftell).
  298. ~pabrec();
  299. public:
  300. word_t N(void) { return _N[0]; }
  301. word_t operator[](int i) { return _w[i]; }
  302. const char *getEntry(int i);
  303. public:
  304. content_t read(word_t offset);
  305. };
  306. */
  307. pabrec::pabrec(pab & P)
  308. {
  309. adr_t A=P.tell();
  310. content_t hdr;
  311. word_t offset,size,dummy;
  312. int i;
  313. hdr=P.go(A);
  314. offset=P.lower(hdr);
  315. size=offset;
  316. _mem=new byte[size];
  317. P.read(_mem,size);
  318. P.go(A+offset);
  319. P.read(m_N);
  320. m_W=new word_t[m_N+1];
  321. P.read(dummy);
  322. for(i=0;i<=m_N;i++) {
  323. P.read(m_W[i]);
  324. }
  325. }
  326. pabrec::~pabrec()
  327. {
  328. delete _mem;
  329. delete m_W;
  330. }
  331. content_t pabrec::read(word_t offset)
  332. {
  333. content_t R;
  334. R=_mem[offset+3];
  335. R<<=8;R+=_mem[offset+2];
  336. R<<=8;R+=_mem[offset+1];
  337. R<<=8;R+=_mem[offset];
  338. return R;
  339. }
  340. const char *pabrec::getEntry(int i)
  341. {
  342. int mb,me;
  343. int k;
  344. mb=m_W[i];me=m_W[i+1];
  345. for(k=0;mb!=me;mb++) {
  346. if (_mem[mb]>=' ' || _mem[mb]=='\n' || _mem[mb]==13 || _mem[mb]=='\t') {
  347. if (_mem[mb]==13) { entry[k]='\n'; }
  348. else { entry[k]=_mem[mb]; }
  349. k+=1;
  350. }
  351. }
  352. entry[k]='\0';
  353. return (const char *) entry;
  354. }