[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    [Kde-pim] Re: Fwd: failure notice [pine addressbook import/export]
From:       Amit Upadhyay <upadhyay () me ! iitb ! ac ! in>
Date:       2002-09-16 19:53:33
[Download RAW message or body]

On Monday 16 Sep 2002 1:57 am, Amit Upadhyay wrote:
> On Mon, 16 Sep 2002, Amit Upadhyay wrote:
>
> ~ On Monday 16 Sep 2002 12:59 am, you wrote:
> ~
> ~ Patch for including Pine addressbook import support for kmailcvt.
> ~
> ~ I am adding two files there.
>
> Oops, I missed something [ pine lets u have email address fields like
> "Amit Upadhyay <upadhyay@me.iitb.ac.in>" which with name "Amit" becomes
> "Amit <Amit Upadhyay<upadhyay@me.iitb.ac.in>>" when selecting it, and
> trying to compose a new mail, in kaddressbook ]. Will send a patch
> sometime tomorrow, in India its already 2AM in the morning...

Here is the second version of my patch. [commented out a few cout-s, converted 
cerr to info->alert(), better message in aborted import, and obviously 
stripped emails to tackle said problem.]

Trivial problem:
* File Selection Dialog when selecting the pine addressbook, has a glob string 
= "*", but then only regular files are shown there. Default pine addressbook 
is .addressbook, a hidden file. What should be the glob string, such that I 
can show the users all the hidden files.

Small problems:
* Nicknames lost.
* Fcc-s Lost.
* If there are more than one email addresses, second onwards are lost.

All three can be solved if I go about changing the basic framework designed by 
Hans Dijkema etc, which blissfully ignores such scenarios. I can either 
ignore the filter framework suggestions in the Adding_Filters.html and talk 
with kabc directly, or modify the framework and related documentations etc to 
include them. Function overloading will make sure that already existing 
filters are not broken.

Big Problem:
* There is no way of distinguishing between email-lists and regular contacts. 
Right now, I am dumping all the entries in pine addressbook to kabc as 
regular contact. If we arent much fussy about it, we can leave a note to user 
about this limitation. Second option is to prompt the user to decide for all 
the entries which contain more than one email address. Though this slows down 
things a bit, I guess user wont mind it much...[she has already seen the cool 
features of kmail and is greatly excited about it, switching from pine to it, 
and all the time she is pressing "Email-List"/"Regular Contact" button, she 
will be cursing pine developers for doing such a stupid thing ;)]

Some may please comment if I am going in right directions, so that I can go 
ahead and solve some of these problems. 


Regards,
-- 
Amit Upadhyay
Senior Undergraduate Student
Department of Mechanical Engg.
Indian Institute of Technology Bombay
Mumbai-76, India
Phone: (91) 9820325940 
["kmailcvt.patch" (text/x-diff)]

? kmailcvt/filter_pine_ab.cxx
? kmailcvt/filter_pine_ab.hxx
Index: kmailcvt/Makefile.am
===================================================================
RCS file: /home/kde/kdenetwork/kmailcvt/Makefile.am,v
retrieving revision 1.12
diff -u -3 -p -r1.12 Makefile.am
--- kmailcvt/Makefile.am	22 Jun 2002 21:45:08 -0000	1.12
+++ kmailcvt/Makefile.am	15 Sep 2002 19:50:36 -0000
@@ -1,9 +1,9 @@
 
 bin_PROGRAMS = kmailcvt
-kmailcvt_SOURCES = oe4_2mbox.cpp liboe.cxx filter_oe4.cxx oe5_2mbox.cpp pablib.cxx \
mapihd.cpp filters.cxx filter_pab.cxx filter_oe5.cxx kmailcvt.cpp main.cpp \
filter_eudora_ab.cxx filter_ldif.cxx filter_pmail.cxx filter_plain.cxx \
+kmailcvt_SOURCES = oe4_2mbox.cpp liboe.cxx filter_oe4.cxx oe5_2mbox.cpp pablib.cxx \
mapihd.cpp filters.cxx filter_pab.cxx filter_oe5.cxx kmailcvt.cpp main.cpp \
filter_eudora_ab.cxx filter_pine_ab.cxx filter_ldif.cxx filter_pmail.cxx \
filter_plain.cxx  kmailcvt_LDADD   = -lkabc $(LIB_KFILE)
 
-EXTRA_DIST = main.cpp kmailcvt.cpp kmailcvt.h kmailcvt.desktop filter_oe5.cxx \
filter_oe5.hxx filter_eudora_ab.cxx filter_eudora_ab.hxx filter_pab.cxx \
filter_pab.hxx filters.cxx filters.hxx harray.hxx mapihd.cpp mapihd.h pablib.cxx \
pablib.hxx pabtypes.h liboe.h oe5_2mbox.cpp oe5_2mbox.h filter_oe4.cxx filter_oe4.hxx \
liboe.cxx oe4_2mbox.cpp oe4_2mbox.h PAB_format.html sv9429424.gif filter_ldif.hxx \
filter_ldif.cxx filter_pmail.cxx filter_pmail.hxx filter_plain.cxx filter_plain.hxx \
+EXTRA_DIST = main.cpp kmailcvt.cpp kmailcvt.h kmailcvt.desktop filter_oe5.cxx \
filter_oe5.hxx filter_pine_ab.hxx filter_pine_ab.cxx filter_eudora_ab.cxx \
filter_eudora_ab.hxx filter_pab.cxx filter_pab.hxx filters.cxx filters.hxx harray.hxx \
mapihd.cpp mapihd.h pablib.cxx pablib.hxx pabtypes.h liboe.h oe5_2mbox.cpp \
oe5_2mbox.h filter_oe4.cxx filter_oe4.hxx liboe.cxx oe4_2mbox.cpp oe4_2mbox.h \
PAB_format.html sv9429424.gif filter_ldif.hxx filter_ldif.cxx filter_pmail.cxx \
filter_pmail.hxx filter_plain.cxx filter_plain.hxx  
 install-data-local: uninstall.desktop
 	$(mkinstalldirs) $(DESTDIR)$(kde_appsdir)/Utilities
Index: kmailcvt/filter_eudora_ab.cxx
===================================================================
RCS file: /home/kde/kdenetwork/kmailcvt/filter_eudora_ab.cxx,v
retrieving revision 1.9
diff -u -3 -p -r1.9 filter_eudora_ab.cxx
--- kmailcvt/filter_eudora_ab.cxx	14 Aug 2002 18:14:20 -0000	1.9
+++ kmailcvt/filter_eudora_ab.cxx	15 Sep 2002 19:50:36 -0000
@@ -31,7 +31,7 @@ filter_eudora_ab::filter_eudora_ab() : f
 {
   CAP=i18n("Import Filter for Eudora Light Addressbook");
   LINES=0;
-  printf("name\n");
+//  printf("name\n");
 }
 
 filter_eudora_ab::~filter_eudora_ab()
Index: kmailcvt/filter_ldif.cxx
===================================================================
RCS file: /home/kde/kdenetwork/kmailcvt/filter_ldif.cxx,v
retrieving revision 1.11
diff -u -3 -p -r1.11 filter_ldif.cxx
--- kmailcvt/filter_ldif.cxx	18 Jul 2002 12:06:58 -0000	1.11
+++ kmailcvt/filter_ldif.cxx	15 Sep 2002 19:50:36 -0000
@@ -35,7 +35,7 @@ void filter_ldif::import(filterInfo *inf
 	 char     file[1024];
    char     dir[1024];
    QWidget *parent=info->parent();
-   std::cout << parent << std::endl;
+//   std::cout << parent << std::endl;
 
    sprintf(dir,getenv("HOME"));
 
Index: kmailcvt/kmailcvt.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmailcvt/kmailcvt.cpp,v
retrieving revision 1.12
diff -u -3 -p -r1.12 kmailcvt.cpp
--- kmailcvt/kmailcvt.cpp	20 Jul 2002 01:02:19 -0000	1.12
+++ kmailcvt/kmailcvt.cpp	15 Sep 2002 19:50:36 -0000
@@ -33,6 +33,7 @@
 #include "filter_plain.hxx"
 #include "filter_pab.hxx"
 #include "filter_eudora_ab.hxx"
+#include "filter_pine_ab.hxx"
 #include "filter_ldif.hxx"
 
 void Kmailcvt2::doFilters(void)
@@ -44,6 +45,7 @@ void Kmailcvt2::doFilters(void)
   imports->add(new filter_pab);
   imports->add(new filter_ldif);
   imports->add(new filter_eudora_ab);
+  imports->add(new filter_pine_ab);
 }
 
 


["filter_pine_ab.cxx" (text/x-c++src)]

/***************************************************************************
                          filter_pine_ab.cxx  -  description
                          ------------------------------------
    begin                : San Sept 08 2002
    copyright            : (C) 2002 by Amit Upadhyay
    email                : n8d10021@rediffmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#include <qstring.h>
#include <qstringlist.h>
#include <qfile.h>

#include <klocale.h>
#include <kfiledialog.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>


#include <vector.h>

#include "filter_pine_ab.hxx"

void PineContact::clear(){
        this->nick = this->name = this->fcc = this->comment = "";
        this->emailList = QStringList::split("", "");
}

void PineContact::read ( QString tstr ){
        this->clear();
        QStringList tstrlist= QStringList::split("\t", tstr, true);
        this->nick = tstrlist[0];
        if(tstrlist.size()>1){
                this->name=tstrlist[1];
                if(tstrlist.size()>2){
                        // clean up the email list!!
                        // it shud be of the form (something, somethingelse, ...)
                        tstrlist[2].stripWhiteSpace();
			if(tstrlist[2].startsWith("(")){
	                        tstrlist[2].remove(0,1);
        	                tstrlist[2].remove(tstrlist[2].length()-1,1);
			}
                        this->emailList = QStringList::split(",", tstrlist[2]);
                        if(tstrlist.size()>3){
                                this->fcc = tstrlist[3];
                                if(tstrlist.size()>4){
                                        this->comment = tstrlist[4];
                                }
                        }
                }
        }

}

QString PineContact::write(){
        QString str = this->nick+"\t"+this->name;
        if(emailList.size()>1){
                str += "\t(" + emailList.join(",\n   ") +  ")";
        } else {
                str += "\t"+emailList[0];
        }
        return str+"\n";
}

QString PineContact::strippedEmail(QString email){
	QString temail = "";
	if(!email.contains("<")){
		return email;
	}
	temail=email.section('<', 1, 1);
	return temail.section('>', 0, 0);
			
}
filter_pine_ab :: filter_pine_ab () : filter (i18n("Import Filter for Pine \
Addressbook"), "Amit Upadhyay"){  return;

}

filter_pine_ab::~filter_pine_ab(){}

void filter_pine_ab::import(filterInfo *info) {
	QString pine_ab;
	QWidget *parent = info->parent();
     	if (!kabStart(info)) {
	       	info->alert(name(),i18n("Unable to open KAddressbook"));
     	}

	pine_ab = KFileDialog::getOpenFileName(getenv("HOME"),"*",parent);

	if (pine_ab.length()==0) {
	   	info->alert(name(),i18n("No Addressbook chosen"));
	   	return;
     	}
       
	QString from=i18n("Source: "),to=i18n("Destination: ");
   	from+="\t\t";from+=pine_ab;
	to+="\t";to+=i18n("The K Addressbook");
   	info->from(from);
   	info->to(to);
   	info->current(i18n("Currently converting Pine Addressbook to K Addressbook"));


	QFile addbk(pine_ab);

        if ( !addbk.open(IO_ReadOnly)) { 
		info->alert(name(),i18n("Can not open Addressbook")); 
		info->current(i18n("Conversion Failed, Selected addressbook file cant be \
opened."));  return; 
	}

        QTextStream st(&addbk);
//      vector <PineContact> contacts;
        PineContact tcontact;

        QString tstr,tstr2="";
        QStringList tstrlist,temlist;
        bool carryon = false,firstline=true;

        // all of this carryon shit is coz i dont know if we have something analogous \
to java's peek  // in file reading. I tried google but no use.
        //
        // Now that I cant peek, or unread a character/line back into the stream, I \
                am working in terms
        // of lines, and the extra line i will read [ that is the one not starting \
                with a blank space,
        // indicating next contact ] i will put in a buffer and set the carryon flag.

	while (!st.eof()){
                tstr="";
                if(carryon){
                        tstr = tstr2;
                        tstr2="";
                        carryon = false;
                }
                // try to read the next line and check if it starts with a space.
                while(!st.eof()){
                        tstr2 = st.readLine();
                        if( !firstline &&  !tstr2.startsWith(" ")){
                                carryon=true;
                                break;
                        }
			firstline = false; 
                        tstr+=tstr2;
                        tstr2="";
                }

                // at this point we shuold have in tstr, all the lines associated \
with one contact.  
		tcontact.read(tstr);
		
//              contacts.push_back(tcontact);

		// insert the contact in kabc!
		// right now the biggest problem is how to distinguish between contact and email \
list!!  // pine make no effort to do it for us.. an entry with a single email address \
can safely be  // assumed to be a contact.. 
		
		// oops there is no nickname in filters::kab:kabAddress :((
		// ignoring it for now... 

		kabAddress(info,"Pine Addressbook",
                      tcontact.name,tcontact.strippedEmail(tcontact.emailList[0]),
                      KAB_NIL,KAB_NIL,
		      tcontact.name,
                      KAB_NIL,KAB_NIL,
                      KAB_NIL,KAB_NIL,
                      KAB_NIL,
                      KAB_NIL,KAB_NIL,
                      KAB_NIL,KAB_NIL,
                      KAB_NIL,KAB_NIL,
                      KAB_NIL,KAB_NIL,
                      KAB_NIL,KAB_NIL,KAB_NIL,
                      (tcontact.comment=="") ? KAB_NIL : tcontact.comment, KAB_NIL);
// 		cout << "T: " << tcontact.write().latin1();
	}
	info->current(100.0);
	info->overall(100.0);
     	info->current(i18n("Finished converting Pine address file to K Addressbook"));

	kabStop(info);


}


["filter_pine_ab.hxx" (text/plain)]

/***************************************************************************
                        filter_pine_ab.hxx  -  description
                        ------------------------------------
    begin                : San Sept 8 2002
    copyright            : (C) 2002 Amit Upadhyay
    email                : n8d10021@rediffmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <vector.h>

#include "filters.hxx"

#ifndef __FILTER_PINE_AB__
#define __FILTER_PINE_AB__

class PineContact {
		public:
                QString nick, name, fcc, comment;
                QStringList emailList;
                void clear();
                void read(QString);
                QString write();
                QString strippedEmail(QString);
};



class filter_pine_ab : public filter{
		private:
			  vector<PineContact> contacts;	
		
		public:
			  filter_pine_ab();
			  ~filter_pine_ab();
		
  			  void import(filterInfo *info);
};

#endif

_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic