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.

334 lines
6.2KB

  1. /***************************************************************************
  2. pablib.cxx - description
  3. -------------------
  4. begin : Tue Jul 4 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. #define REC_OK PAB_REC_OK
  18. pab::pab(const char *_pabfile)
  19. {
  20. pabfile=_pabfile;
  21. in.setName(pabfile);
  22. in.open(IO_ReadOnly);
  23. cap=i18n("Import MS Exchange Personal Address Book (.PAB)");
  24. }
  25. pab::~pab()
  26. {
  27. if (in.isOpen()) { in.close(); }
  28. }
  29. //////////////////////////////////////////////////////////////////////
  30. //
  31. // Main conversion
  32. //
  33. //////////////////////////////////////////////////////////////////////
  34. bool pab::convert(void)
  35. {
  36. adr_t A;
  37. bool ret;
  38. if (!in.isOpen()) {TQString msg;
  39. msg=i18n("Cannot open %1 for reading").tqarg(pabfile);
  40. // info->alert(msg);
  41. return false;
  42. }
  43. if (!knownPAB()) {
  44. return false;
  45. }
  46. /*
  47. if (!f->openAddressBook(info)) {
  48. return false;
  49. }
  50. */
  51. A=go(INDEX_OF_INDEX);
  52. ret=convert(A,0,0);
  53. // f->closeAddressBook();
  54. return ret;
  55. }
  56. bool pab::convert(adr_t A,content_t ,content_t )
  57. {
  58. adr_t table;
  59. content_t start,stop,T;
  60. int n, N = 0;
  61. go(A);
  62. T=read();
  63. // Now we have to decide if this is a distribution list
  64. // or an addressbook container. If it is the last just
  65. // jump directly to dotable().
  66. //if (upper(T)==PAB_REC_OK) {
  67. // dotable(A,strt,stp);
  68. // return true;
  69. //}
  70. // OK, it's not an addressbook container,
  71. // handle it like a distribution list
  72. start=T;
  73. while(start!=0) {
  74. N+=1;
  75. stop=read();
  76. table=read();
  77. start=read();
  78. }
  79. if (N==0) { N=1; }
  80. /* {char m[100];
  81. sprintf(m,"%d",N);
  82. info->alert("",m);
  83. }*/
  84. //A=go(INDEX_OF_INDEX);
  85. //printf("IoI=%08lx\n",A);
  86. go(A);
  87. start=read();
  88. n=0;
  89. while(start!=0) {adr_t cp;
  90. stop=read();
  91. table=read();
  92. cp=tell();
  93. dotable(table,start,stop);
  94. //convert(table,start,stop);
  95. go(cp);
  96. start=read();
  97. n+=1;
  98. // info->setOverall( 100 * n / N );
  99. }
  100. return true;
  101. }
  102. void pab::dotable(adr_t T,content_t start,content_t stop)
  103. {
  104. adr_t REC,pREC,cp;
  105. content_t cmp,skip;
  106. int N,n;
  107. go(T);
  108. cp=tell();
  109. REC=0xffffffff;
  110. pREC=0;
  111. cmp=read();
  112. if (cmp!=start) {
  113. // first try processing as if this was a record. I.e. at the stop thing
  114. processRec(stop);
  115. // Then exit
  116. // info->setCurrent();
  117. // info->setCurrent(100);
  118. return;
  119. } // This is not a table.
  120. // info->setCurrent();
  121. N=0;
  122. while (cmp!=stop && REC!=pREC) {
  123. pREC=REC;
  124. REC=read();
  125. if (REC!=pREC) {
  126. skip=read();
  127. cmp=read();
  128. }
  129. N+=1;
  130. }
  131. go(cp);
  132. REC=0xffffffff;
  133. pREC=0;
  134. cmp=read();
  135. n=0;
  136. while(cmp!=stop && REC!=pREC) {adr_t cp;
  137. pREC=REC;
  138. REC=read();
  139. if (REC!=pREC) {
  140. skip=read();
  141. cp=tell();
  142. processRec(REC);
  143. go(cp);
  144. cmp=read();
  145. }
  146. n+=1;
  147. // info->setCurrent(100 * n / N);
  148. }
  149. // info->setCurrent();
  150. // info->setCurrent(100);
  151. }
  152. void pab::processRec(adr_t REC)
  153. {
  154. content_t hdr;
  155. hdr=go(REC);
  156. if (upper(hdr)==REC_OK) { // Now read a record and instantiate!
  157. pabrec rec(*this);
  158. pabfields_t fields(rec, NULL);
  159. if (fields.isOK() && fields.isUsable()) {
  160. // f->addContact( fields.get() );
  161. }
  162. }
  163. }
  164. void pab::prt(unsigned char *,pabrec &,pabrec_entry )
  165. {
  166. }
  167. #define PABREC_N (sizeof(pabrec)/sizeof(word_t))
  168. void pab::rdPabRec(pabrec & )
  169. {
  170. }
  171. //////////////////////////////////////////////////////////////////////
  172. //
  173. // Here's where we recognize the record types
  174. //
  175. //////////////////////////////////////////////////////////////////////
  176. bool pab::recUnknown(pabrec &)
  177. {
  178. return false;
  179. }
  180. bool pab::recNoFunction(pabrec & )
  181. {
  182. return false;
  183. }
  184. const char *pab::get(unsigned char *,pabrec_entry ,pabrec & )
  185. {
  186. return "";
  187. }
  188. void pab::getrange(pabrec & ,pabrec_entry ,word_t & ,word_t & )
  189. {
  190. }
  191. //////////////////////////////////////////////////////////////////////
  192. //
  193. // Here's where we recognize the PAB files
  194. //
  195. //////////////////////////////////////////////////////////////////////
  196. bool pab::knownPAB(void)
  197. {
  198. content_t id;
  199. id=go(0);
  200. if (id!=PAB_FILE_ID) {TQString msg;
  201. msg=i18n("%1 has no PAB id that I know of, cannot convert this").tqarg(pabfile);
  202. // info->alert(msg);
  203. return false;
  204. }
  205. return true;
  206. }
  207. //////////////////////////////////////////////////////////////////////
  208. //
  209. // Functions to do file reading/positioning
  210. //
  211. //////////////////////////////////////////////////////////////////////
  212. content_t pab::go(adr_t a)
  213. {
  214. content_t A;
  215. in.at(a);
  216. A=read();
  217. in.at(a);
  218. return A;
  219. }
  220. content_t pab::read(void)
  221. {
  222. unsigned char mem[4];
  223. content_t A;
  224. in.readBlock((char *) &mem, sizeof(A)); // WinTel unsigned long opslag
  225. A=mem[3];
  226. A<<=8;A|=mem[2];
  227. A<<=8;A|=mem[1];
  228. A<<=8;A|=mem[0];
  229. return A;
  230. }
  231. void pab::read(word_t & w)
  232. {
  233. unsigned char mem[2];
  234. in.readBlock((char *) &mem, sizeof(w));
  235. w=mem[1];
  236. w<<=8;w|=mem[0];
  237. }
  238. content_t pab::relative(int words)
  239. {
  240. adr_t a;
  241. a=in.at();
  242. return go(a+(words*sizeof(content_t)));
  243. }
  244. content_t pab::add(adr_t & A,int words)
  245. {
  246. A+=(words*sizeof(content_t));
  247. return go(A);
  248. }
  249. pabsize_t pab::size(content_t A)
  250. {
  251. return A&0xFFFF;
  252. }
  253. word_t pab::lower(content_t A)
  254. {
  255. return A&0xFFFF;
  256. }
  257. word_t pab::upper(content_t A)
  258. {
  259. return A>>16;
  260. }
  261. void pab::size(content_t A,pabsize_t & s1,pabsize_t & s2)
  262. {
  263. s1=A&0xFFFF;
  264. s2>>=16;
  265. }
  266. byte_t pab::readbyte(void)
  267. {
  268. byte_t c;
  269. c=in.getch();
  270. return c;
  271. }
  272. void pab::read(unsigned char *mem,content_t size)
  273. {
  274. in.readBlock((char *) mem, size);
  275. }