claws-mail/src/addritem.c

1490 lines
39 KiB
C
Raw Normal View History

2001-09-02 01:48:06 +02:00
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
2006-01-13 [paul] 1.9.100cvs142 * src/account.c * src/account.h * src/action.c * src/action.h * src/adbookbase.h * src/addr_compl.c * src/addr_compl.h * src/addrbook.c * src/addrcache.c * src/addrcache.h * src/addrcindex.c * src/addrcindex.h * src/addrclip.c * src/addrclip.h * src/addrdefs.h * src/addressadd.c * src/addressadd.h * src/addressbook.c * src/addressbook.h * src/addrgather.c * src/addrgather.h * src/addrharvest.c * src/addrharvest.h * src/addrindex.c * src/addrindex.h * src/addritem.c * src/addritem.h * src/addrquery.c * src/addrquery.h * src/addrselect.c * src/addrselect.h * src/alertpanel.c * src/alertpanel.h * src/browseldap.c * src/browseldap.h * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/customheader.c * src/customheader.h * src/displayheader.c * src/displayheader.h * src/editaddress.c * src/editaddress.h * src/editbook.c * src/editbook.h * src/editgroup.c * src/editgroup.h * src/editjpilot.c * src/editjpilot.h * src/editldap.c * src/editldap.h * src/editldap_basedn.c * src/editldap_basedn.h * src/editvcard.c * src/editvcard.h * src/exphtmldlg.c * src/exphtmldlg.h * src/expldifdlg.c * src/expldifdlg.h * src/export.h * src/exporthtml.c * src/exporthtml.h * src/exportldif.c * src/exportldif.h * src/filtering.c * src/filtering.h * src/folder.c * src/folder.h * src/folder_item_prefs.c * src/folder_item_prefs.h * src/foldersel.c * src/foldersel.h * src/folderutils.c * src/folderutils.h * src/folderview.c * src/folderview.h * src/grouplistdialog.c * src/grouplistdialog.h * src/headerview.c * src/html.c * src/html.h * src/image_viewer.c * src/image_viewer.h * src/imap.c * src/imap.h * src/imap_gtk.c * src/imap_gtk.h * src/import.h * src/importldif.c * src/importldif.h * src/importmutt.c * src/importmutt.h * src/importpine.c * src/importpine.h * src/inc.c * src/inc.h * src/jpilot.c * src/jpilot.h * src/ldapctrl.c * src/ldapctrl.h * src/ldaplocate.c * src/ldaplocate.h * src/ldapquery.c * src/ldapquery.h * src/ldapserver.c * src/ldapserver.h * src/ldaputil.c * src/ldaputil.h * src/ldif.c * src/ldif.h * src/main.c * src/main.h * src/mainwindow.c * src/mainwindow.h * src/manual.c * src/manual.h * src/mbox.c * src/mbox.h * src/message_search.c * src/message_search.h * src/messageview.c * src/messageview.h * src/mh.c * src/mh.h * src/mh_gtk.c * src/mh_gtk.h * src/mimeview.c * src/mimeview.h * src/msgcache.c * src/msgcache.h * src/mutt.c * src/mutt.h * src/news.c * src/news.h * src/news_gtk.c * src/news_gtk.h * src/partial_download.c * src/partial_download.h * src/pine.c * src/pine.h * src/pop.c * src/pop.h * src/prefs_account.c * src/prefs_account.h * src/prefs_actions.c * src/prefs_actions.h * src/prefs_common.c * src/prefs_common.h * src/prefs_compose_writing.c * src/prefs_compose_writing.h * src/prefs_customheader.c * src/prefs_customheader.h * src/prefs_display_header.c * src/prefs_display_header.h * src/prefs_filtering.c * src/prefs_filtering.h * src/prefs_filtering_action.c * src/prefs_filtering_action.h * src/prefs_folder_column.c * src/prefs_folder_column.h * src/prefs_folder_item.c * src/prefs_folder_item.h * src/prefs_fonts.c * src/prefs_fonts.h * src/prefs_gtk.c * src/prefs_gtk.h * src/prefs_image_viewer.c * src/prefs_image_viewer.h * src/prefs_matcher.c * src/prefs_matcher.h * src/prefs_message.c * src/prefs_msg_colors.c * src/prefs_msg_colors.h * src/prefs_other.c * src/prefs_quote.c * src/prefs_receive.c * src/prefs_send.c * src/prefs_spelling.c * src/prefs_spelling.h * src/prefs_summaries.c * src/prefs_summaries.h * src/prefs_summary_column.c * src/prefs_summary_column.h * src/prefs_template.c * src/prefs_template.h * src/prefs_themes.c * src/prefs_themes.h * src/prefs_toolbar.c * src/prefs_toolbar.h * src/prefs_wrapping.c * src/prefs_wrapping.h * src/privacy.c * src/privacy.h * src/procheader.c * src/procheader.h * src/procmime.c * src/procmime.h * src/procmsg.c * src/procmsg.h * src/quote_fmt.c * src/quote_fmt_parse.y * src/recv.c * src/recv.h * src/remotefolder.c * src/remotefolder.h * src/send_message.c * src/send_message.h * src/setup.c * src/setup.h * src/sourcewindow.c * src/sourcewindow.h * src/ssl_manager.c * src/ssl_manager.h * src/statusbar.c * src/statusbar.h * src/stock_pixmap.c * src/stock_pixmap.h * src/summary_search.c * src/summary_search.h * src/summaryview.c * src/summaryview.h * src/syldap.c * src/syldap.h * src/textview.c * src/textview.h * src/toolbar.c * src/toolbar.h * src/undo.c * src/undo.h * src/unmime.c * src/unmime.h * src/vcard.c * src/vcard.h * src/wizard.c * src/wizard.h * src/common/base64.c * src/common/base64.h * src/common/defs.h * src/common/hooks.c * src/common/hooks.h * src/common/log.c * src/common/log.h * src/common/mgutils.c * src/common/mgutils.h * src/common/nntp.c * src/common/nntp.h * src/common/passcrypt.c * src/common/passcrypt.h.in * src/common/plugin.c * src/common/plugin.h * src/common/prefs.c * src/common/prefs.h * src/common/progressindicator.c * src/common/progressindicator.h * src/common/quoted-printable.c * src/common/quoted-printable.h * src/common/session.c * src/common/session.h * src/common/smtp.c * src/common/smtp.h * src/common/socket.c * src/common/socket.h * src/common/ssl.c * src/common/ssl.h * src/common/ssl_certificate.c * src/common/ssl_certificate.h * src/common/stringtable.c * src/common/stringtable.h * src/common/sylpheed.c * src/common/sylpheed.h * src/common/template.c * src/common/template.h * src/common/timing.h * src/common/utils.c * src/common/utils.h * src/common/version.h.in * src/common/xml.c * src/common/xml.h * src/common/xmlprops.c * src/common/xmlprops.h * src/gtk/colorlabel.c * src/gtk/colorsel.c * src/gtk/colorsel.h * src/gtk/description_window.c * src/gtk/description_window.h * src/gtk/filesel.c * src/gtk/filesel.h * src/gtk/foldersort.c * src/gtk/foldersort.h * src/gtk/gtkutils.c * src/gtk/gtkutils.h * src/gtk/inputdialog.c * src/gtk/inputdialog.h * src/gtk/logwindow.c * src/gtk/logwindow.h * src/gtk/manage_window.c * src/gtk/manage_window.h * src/gtk/menu.c * src/gtk/menu.h * src/gtk/pluginwindow.c * src/gtk/pluginwindow.h * src/gtk/prefswindow.c * src/gtk/prefswindow.h * src/gtk/progressdialog.c * src/gtk/progressdialog.h * src/gtk/sslcertwindow.c * src/gtk/sslcertwindow.h * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin.h * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_prefs.h * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/pgpcore/passphrase.c * src/plugins/pgpcore/passphrase.h * src/plugins/pgpcore/plugin.c * src/plugins/pgpcore/select-keys.c * src/plugins/pgpcore/select-keys.h * src/plugins/pgpcore/sgpgme.c * src/plugins/pgpcore/sgpgme.h * src/plugins/pgpinline/pgpinline.c * src/plugins/pgpinline/pgpinline.h * src/plugins/pgpinline/plugin.c * src/plugins/pgpmime/pgpmime.c * src/plugins/pgpmime/pgpmime.h * src/plugins/pgpmime/plugin.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin.h * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c update copyright header
2006-01-13 18:24:38 +01:00
* Copyright (C) 2001-2006 Match Grun and the Sylpheed-Claws team
2001-09-02 01:48:06 +02:00
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2005-09-21 [paul] 1.9.14cvs47 * README * README.jp * configure.ac * config/config.rpath * doc/manual/en/sylpheed-20.html * doc/manual/es/sylpheed-20.html * po/bg.po * po/ca.po * po/de.po * po/es.po * po/fr.po * po/it.po * po/pt_BR.po * po/sk.po * po/zh_TW.po * src/account.c * src/account.h * src/action.c * src/action.h * src/adbookbase.h * src/addr_compl.c * src/addr_compl.h * src/addrbook.c * src/addrbook.h * src/addrcache.c * src/addrcache.h * src/addrcindex.c * src/addrcindex.h * src/addrclip.c * src/addrclip.h * src/addrdefs.h * src/addressadd.c * src/addressadd.h * src/addressbook.c * src/addressbook.h * src/addressitem.h * src/addrgather.c * src/addrgather.h * src/addrharvest.c * src/addrharvest.h * src/addrindex.c * src/addrindex.h * src/addritem.c * src/addritem.h * src/addrquery.c * src/addrquery.h * src/addrselect.c * src/addrselect.h * src/alertpanel.c * src/alertpanel.h * src/browseldap.c * src/browseldap.h * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/crash.c * src/crash.h * src/customheader.c * src/customheader.h * src/displayheader.c * src/displayheader.h * src/editaddress.c * src/editaddress.h * src/editbook.c * src/editbook.h * src/editgroup.c * src/editgroup.h * src/editjpilot.c * src/editjpilot.h * src/editldap.c * src/editldap.h * src/editldap_basedn.c * src/editldap_basedn.h * src/editvcard.c * src/editvcard.h * src/enriched.c * src/enriched.h * src/exphtmldlg.c * src/exphtmldlg.h * src/expldifdlg.c * src/expldifdlg.h * src/export.c * src/export.h * src/exporthtml.c * src/exporthtml.h * src/exportldif.c * src/exportldif.h * src/filtering.c * src/filtering.h * src/folder.c * src/folder.h * src/folder_item_prefs.c * src/folder_item_prefs.h * src/foldersel.c * src/foldersel.h * src/folderutils.c * src/folderutils.h * src/folderview.c * src/folderview.h * src/grouplistdialog.c * src/grouplistdialog.h * src/headerview.c * src/headerview.h * src/html.c * src/html.h * src/image_viewer.c * src/image_viewer.h * src/imap.c * src/imap.h * src/imap_gtk.c * src/imap_gtk.h * src/import.c * src/import.h * src/importldif.c * src/importldif.h * src/importmutt.c * src/importmutt.h * src/importpine.c * src/importpine.h * src/inc.c * src/inc.h * src/jpilot.c * src/jpilot.h * src/ldapctrl.c * src/ldapctrl.h * src/ldaplocate.c * src/ldaplocate.h * src/ldapquery.c * src/ldapquery.h * src/ldapserver.c * src/ldapserver.h * src/ldaputil.c * src/ldaputil.h * src/ldif.c * src/ldif.h * src/localfolder.c * src/localfolder.h * src/main.c * src/main.h * src/mainwindow.c * src/mainwindow.h * src/manual.c * src/manual.h * src/matcher.c * src/matcher.h * src/matcher_parser.h * src/matcher_parser_lex.l * src/matcher_parser_parse.y * src/mbox.c * src/mbox.h * src/message_search.c * src/message_search.h * src/messageview.c * src/messageview.h * src/mh.c * src/mh.h * src/mh_gtk.c * src/mh_gtk.h * src/mimeview.c * src/mimeview.h * src/msgcache.c * src/msgcache.h * src/mutt.c * src/mutt.h * src/news.c * src/news.h * src/news_gtk.c * src/news_gtk.h * src/noticeview.c * src/noticeview.h * src/partial_download.c * src/partial_download.h * src/pine.c * src/pine.h * src/pop.c * src/pop.h * src/prefs_account.c * src/prefs_account.h * src/prefs_actions.c * src/prefs_actions.h * src/prefs_common.c * src/prefs_common.h * src/prefs_compose_writing.c * src/prefs_compose_writing.h * src/prefs_customheader.c * src/prefs_customheader.h * src/prefs_display_header.c * src/prefs_display_header.h * src/prefs_ext_prog.c * src/prefs_ext_prog.h * src/prefs_filtering.c * src/prefs_filtering.h * src/prefs_filtering_action.c * src/prefs_filtering_action.h * src/prefs_folder_column.c * src/prefs_folder_column.h * src/prefs_folder_item.c * src/prefs_folder_item.h * src/prefs_fonts.c * src/prefs_fonts.h * src/prefs_gtk.c * src/prefs_gtk.h * src/prefs_image_viewer.c * src/prefs_image_viewer.h * src/prefs_matcher.c * src/prefs_matcher.h * src/prefs_message.c * src/prefs_message.h * src/prefs_msg_colors.c * src/prefs_msg_colors.h * src/prefs_other.c * src/prefs_other.h * src/prefs_quote.c * src/prefs_quote.h * src/prefs_receive.c * src/prefs_receive.h * src/prefs_send.c * src/prefs_send.h * src/prefs_spelling.c * src/prefs_spelling.h * src/prefs_summaries.c * src/prefs_summaries.h * src/prefs_summary_column.c * src/prefs_summary_column.h * src/prefs_template.c * src/prefs_template.h * src/prefs_themes.c * src/prefs_themes.h * src/prefs_toolbar.c * src/prefs_toolbar.h * src/prefs_wrapping.c * src/prefs_wrapping.h * src/privacy.c * src/privacy.h * src/procheader.c * src/procheader.h * src/procmime.c * src/procmime.h * src/procmsg.c * src/procmsg.h * src/quote_fmt.c * src/quote_fmt_parse.y * src/recv.c * src/recv.h * src/remotefolder.c * src/remotefolder.h * src/send_message.c * src/send_message.h * src/setup.c * src/setup.h * src/simple-gettext.c * src/sourcewindow.c * src/sourcewindow.h * src/ssl_manager.c * src/ssl_manager.h * src/statusbar.c * src/statusbar.h * src/stock_pixmap.c * src/stock_pixmap.h * src/summary_search.c * src/summary_search.h * src/summaryview.c * src/summaryview.h * src/syldap.c * src/syldap.h * src/textview.c * src/textview.h * src/toolbar.c * src/toolbar.h * src/undo.c * src/undo.h * src/unmime.c * src/unmime.h * src/vcard.c * src/vcard.h * src/wizard.c * src/wizard.h * src/common/base64.c * src/common/base64.h * src/common/defs.h * src/common/hooks.c * src/common/hooks.h * src/common/log.c * src/common/log.h * src/common/md5.c * src/common/md5.h * src/common/mgutils.c * src/common/mgutils.h * src/common/nntp.c * src/common/nntp.h * src/common/passcrypt.c * src/common/passcrypt.h.in * src/common/plugin.c * src/common/plugin.h * src/common/prefs.c * src/common/prefs.h * src/common/progressindicator.c * src/common/progressindicator.h * src/common/quoted-printable.c * src/common/quoted-printable.h * src/common/session.c * src/common/session.h * src/common/smtp.c * src/common/smtp.h * src/common/socket.c * src/common/socket.h * src/common/ssl.c * src/common/ssl.h * src/common/ssl_certificate.c * src/common/ssl_certificate.h * src/common/string_match.c * src/common/string_match.h * src/common/stringtable.c * src/common/sylpheed.c * src/common/sylpheed.h * src/common/template.c * src/common/template.h * src/common/timing.h * src/common/utils.c * src/common/utils.h * src/common/uuencode.c * src/common/uuencode.h * src/common/version.h.in * src/common/xml.c * src/common/xml.h * src/common/xmlprops.c * src/common/xmlprops.h * src/gtk/about.c * src/gtk/about.h * src/gtk/colorlabel.c * src/gtk/colorlabel.h * src/gtk/colorsel.c * src/gtk/colorsel.h * src/gtk/description_window.c * src/gtk/description_window.h * src/gtk/filesel.c * src/gtk/filesel.h * src/gtk/foldersort.c * src/gtk/foldersort.h * src/gtk/gtkutils.c * src/gtk/gtkutils.h * src/gtk/inputdialog.c * src/gtk/inputdialog.h * src/gtk/logwindow.c * src/gtk/logwindow.h * src/gtk/manage_window.c * src/gtk/manage_window.h * src/gtk/menu.c * src/gtk/menu.h * src/gtk/pluginwindow.c * src/gtk/pluginwindow.h * src/gtk/prefswindow.c * src/gtk/prefswindow.h * src/gtk/progressdialog.c * src/gtk/progressdialog.h * src/gtk/quicksearch.c * src/gtk/quicksearch.h * src/gtk/sslcertwindow.c * src/gtk/sslcertwindow.h * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin.h * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_prefs.h * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/mathml_viewer/mathml_viewer.c * src/plugins/pgpcore/passphrase.c * src/plugins/pgpcore/passphrase.h * src/plugins/pgpcore/plugin.c * src/plugins/pgpcore/prefs_gpg.c * src/plugins/pgpcore/prefs_gpg.h * src/plugins/pgpcore/select-keys.c * src/plugins/pgpcore/select-keys.h * src/plugins/pgpcore/sgpgme.c * src/plugins/pgpcore/sgpgme.h * src/plugins/pgpinline/pgpinline.c * src/plugins/pgpinline/pgpinline.h * src/plugins/pgpinline/plugin.c * src/plugins/pgpmime/pgpmime.c * src/plugins/pgpmime/pgpmime.h * src/plugins/pgpmime/plugin.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin.h * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c * tools/OOo2sylpheed.pl * tools/acroread2sylpheed.pl * tools/asus_mailled.sh * tools/filter_conv.pl * tools/freshmeat_search.pl * tools/google_search.pl * tools/kmail2sylpheed.pl * tools/kmail2sylpheed_v2.pl * tools/maildir2sylpheed.pl * tools/multiwebsearch.pl * tools/newscache_clean.pl * tools/outlook2sylpheed.pl * tools/sylpheed-switcher * tools/update-po * tools/vcard2xml.py * tools/kdeservicemenu/sylpheed-kdeservicemenu.pl update FSF address
2005-09-21 20:22:51 +02:00
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2001-09-02 01:48:06 +02:00
*/
/*
* General primitive address item objects.
*/
#include <glib.h>
2002-03-07 14:22:39 +01:00
#include <stdio.h>
#include <string.h>
2001-09-02 01:48:06 +02:00
2004-01-12 22:28:31 +01:00
#include "utils.h"
2001-09-02 01:48:06 +02:00
#include "addritem.h"
#include "mgutils.h"
#include "codeconv.h"
2001-09-02 01:48:06 +02:00
2003-03-20 00:16:26 +01:00
/**
* Create new email address item.
* \return Initialized email item.
*/
2001-09-02 01:48:06 +02:00
ItemEMail *addritem_create_item_email( void ) {
ItemEMail *item;
item = g_new0( ItemEMail, 1 );
ADDRITEM_TYPE(item) = ITEMTYPE_EMAIL;
ADDRITEM_ID(item) = NULL;
ADDRITEM_NAME(item) = NULL;
ADDRITEM_PARENT(item) = NULL;
ADDRITEM_SUBTYPE(item) = 0;
item->address = NULL;
item->remarks = NULL;
return item;
}
2003-03-20 00:16:26 +01:00
/**
* Create a shallow copy of specified email address item.
* \param item E-Mail to copy.
* \return Copy of email, or <i>NULL</i> if null argument supplied.
*/
2001-09-02 01:48:06 +02:00
ItemEMail *addritem_copy_item_email( ItemEMail *item ) {
ItemEMail *itemNew = NULL;
if( item ) {
itemNew = addritem_create_item_email();
ADDRITEM_NAME(itemNew) = g_strdup( ADDRITEM_NAME(item) );
itemNew->address = g_strdup( item->address );
itemNew->remarks = g_strdup( item->remarks );
}
return itemNew;
}
2003-03-20 00:16:26 +01:00
/**
* Create a full copy (deep copy) of specified email address item.
* \param item E-Mail to copy.
* \return Copy of email.
*/
ItemEMail *addritem_copyfull_item_email( ItemEMail *item ) {
ItemEMail *itemNew = NULL;
if( item ) {
itemNew = addritem_create_item_email();
2001-09-02 01:48:06 +02:00
ADDRITEM_ID(itemNew) = g_strdup( ADDRITEM_ID(item) );
ADDRITEM_NAME(itemNew) = g_strdup( ADDRITEM_NAME(item) );
ADDRITEM_PARENT(itemNew) = ADDRITEM_PARENT(item);
itemNew->address = g_strdup( item->address );
itemNew->remarks = g_strdup( item->remarks );
}
return itemNew;
}
2003-03-20 00:16:26 +01:00
/**
* Specify ID for email.
* \param email E-Mail item.
* \param value ID.
*/
2001-09-02 01:48:06 +02:00
void addritem_email_set_id( ItemEMail *email, const gchar *value ) {
ADDRITEM_ID(email) = mgu_replace_string( ADDRITEM_ID(email), value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify alias for email.
* \param email E-Mail item.
* \param value Alias.
*/
2001-09-02 01:48:06 +02:00
void addritem_email_set_alias( ItemEMail *email, const gchar *value ) {
ADDRITEM_NAME(email) = mgu_replace_string( ADDRITEM_NAME(email), value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify address for email.
* \param email E-Mail item.
* \param value Address.
*/
2001-09-02 01:48:06 +02:00
void addritem_email_set_address( ItemEMail *email, const gchar *value ) {
email->address = mgu_replace_string( email->address, value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify remarks for email.
* \param email E-Mail item.
* \param value Remarks.
*/
2001-09-02 01:48:06 +02:00
void addritem_email_set_remarks( ItemEMail *email, const gchar *value ) {
email->remarks = mgu_replace_string( email->remarks, value );
}
2003-03-20 00:16:26 +01:00
/**
* Free address item email object.
* \param item E-Mail item to free.
*/
2001-09-02 01:48:06 +02:00
void addritem_free_item_email( ItemEMail *item ) {
g_return_if_fail( item != NULL );
/* Free internal stuff */
g_free( ADDRITEM_ID(item) );
g_free( ADDRITEM_NAME(item) );
g_free( item->address );
g_free( item->remarks );
ADDRITEM_OBJECT(item)->type = ITEMTYPE_NONE;
ADDRITEM_ID(item) = NULL;
ADDRITEM_NAME(item) = NULL;
ADDRITEM_PARENT(item) = NULL;
ADDRITEM_SUBTYPE(item) = 0;
item->address = NULL;
item->remarks = NULL;
g_free( item );
}
2003-03-20 00:16:26 +01:00
/**
* Create new attribute object.
* \return Initialized attribute object.
*/
2001-09-02 01:48:06 +02:00
UserAttribute *addritem_create_attribute( void ) {
UserAttribute *item;
item = g_new0( UserAttribute, 1 );
item->uid = NULL;
item->name = NULL;
item->value = NULL;
return item;
}
2003-03-20 00:16:26 +01:00
/**
* Create copy (deep copy) of specified attribute.
* \param item Attribute to copy.
* \return Copy of attribute, or <i>NULL</i> if null argument supplied.
*/
2001-09-02 01:48:06 +02:00
UserAttribute *addritem_copy_attribute( UserAttribute *item ) {
UserAttribute *itemNew = NULL;
if( item ) {
itemNew = addritem_create_attribute();
itemNew->uid = g_strdup( item->uid );
itemNew->name = g_strdup( item->name );
itemNew->value = g_strdup( item->value );
}
return itemNew;
}
2003-03-20 00:16:26 +01:00
/**
* Specify ID for attribute.
* \param item Attribute object.
* \param value ID.
*/
2001-09-02 01:48:06 +02:00
void addritem_attrib_set_id( UserAttribute *item, const gchar *value ) {
g_return_if_fail( item != NULL );
item->uid = mgu_replace_string( item->uid, value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify name for attribute.
* \param item Attribute object.
* \param value Name.
*/
2001-09-02 01:48:06 +02:00
void addritem_attrib_set_name( UserAttribute *item, const gchar *value ) {
g_return_if_fail( item != NULL );
item->name = mgu_replace_string( item->name, value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify value for attribute.
* \param item Attribute object.
* \param value Value.
*/
2001-09-02 01:48:06 +02:00
void addritem_attrib_set_value( UserAttribute *item, const gchar *value ) {
g_return_if_fail( item != NULL );
item->value = mgu_replace_string( item->value, value );
}
2003-03-20 00:16:26 +01:00
/**
* Free user attribute.
* \param item Attribute object to free.
*/
2001-09-02 01:48:06 +02:00
void addritem_free_attribute( UserAttribute *item ) {
g_return_if_fail( item != NULL );
g_free( item->uid );
g_free( item->name );
g_free( item->value );
item->uid = NULL;
item->name = NULL;
item->value = NULL;
g_free( item );
}
2003-03-20 00:16:26 +01:00
/**
* Create new address book person.
* \return Initialized person object.
*/
2001-09-02 01:48:06 +02:00
ItemPerson *addritem_create_item_person( void ) {
ItemPerson *person;
person = g_new0( ItemPerson, 1 );
ADDRITEM_TYPE(person) = ITEMTYPE_PERSON;
ADDRITEM_ID(person) = NULL;
ADDRITEM_NAME(person) = NULL;
ADDRITEM_PARENT(person) = NULL;
ADDRITEM_SUBTYPE(person) = 0;
person->firstName = NULL;
person->lastName = NULL;
person->nickName = NULL;
person->listEMail = NULL;
person->listAttrib = NULL;
person->externalID = NULL;
person->isOpened = FALSE;
return person;
}
2003-03-20 00:16:26 +01:00
/**
* Create a shallow copy of address book person object.
* \param item Person to copy.
* \return Copy of person, or <i>NULL</i> if null argument supplied.
*/
ItemPerson *addritem_copy_item_person( ItemPerson *item ) {
ItemPerson *itemNew;
itemNew = NULL;
if( item ) {
itemNew = addritem_create_item_person();
ADDRITEM_NAME(itemNew) = g_strdup( ADDRITEM_NAME(item) );
itemNew->firstName = g_strdup( item->firstName );
itemNew->lastName = g_strdup( item->lastName );
itemNew->nickName = g_strdup( item->nickName );
itemNew->externalID = g_strdup( item->externalID );
}
return itemNew;
}
2003-03-20 00:16:26 +01:00
/**
* Specify ID for person object.
* \param person Person object.
* \param value ID.
*/
2001-09-02 01:48:06 +02:00
void addritem_person_set_id( ItemPerson *person, const gchar *value ) {
ADDRITEM_ID(person) = mgu_replace_string( ADDRITEM_ID(person), value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify first name for person object.
* \param person Person object.
* \param value Name.
*/
2001-09-02 01:48:06 +02:00
void addritem_person_set_first_name( ItemPerson *person, const gchar *value ) {
if (!value || g_utf8_validate(value, -1, NULL))
person->firstName = mgu_replace_string( person->firstName, value );
else {
gchar *out = conv_codeset_strdup(value,
conv_get_locale_charset_str_no_utf8(),
CS_INTERNAL);
if (out)
person->firstName = mgu_replace_string( person->firstName, out );
g_free(out);
}
2001-09-02 01:48:06 +02:00
}
2003-03-20 00:16:26 +01:00
/**
* Specify last name for person object.
* \param person Person object.
* \param value name.
*/
2001-09-02 01:48:06 +02:00
void addritem_person_set_last_name( ItemPerson *person, const gchar *value ) {
if (!value || g_utf8_validate(value, -1, NULL))
person->lastName = mgu_replace_string( person->lastName, value );
else {
gchar *out = conv_codeset_strdup(value,
conv_get_locale_charset_str_no_utf8(),
CS_INTERNAL);
if (out)
person->lastName = mgu_replace_string( person->lastName, out );
g_free(out);
}
2001-09-02 01:48:06 +02:00
}
2003-03-20 00:16:26 +01:00
/**
* Specify nick name for person object.
* \param person Person object.
* \param value name.
*/
2001-09-02 01:48:06 +02:00
void addritem_person_set_nick_name( ItemPerson *person, const gchar *value ) {
if (!value || g_utf8_validate(value, -1, NULL))
person->nickName = mgu_replace_string( person->nickName, value );
else {
gchar *out = conv_codeset_strdup(value,
conv_get_locale_charset_str_no_utf8(),
CS_INTERNAL);
if (out)
person->nickName = mgu_replace_string( person->nickName, out );
g_free(out);
}
2001-09-02 01:48:06 +02:00
}
2003-03-20 00:16:26 +01:00
/**
* Specify common name for person object.
* \param person Person object.
* \param value name.
*/
2001-09-02 01:48:06 +02:00
void addritem_person_set_common_name( ItemPerson *person, const gchar *value ) {
if (!value || g_utf8_validate(value, -1, NULL))
ADDRITEM_NAME(person) = mgu_replace_string( ADDRITEM_NAME(person), value );
else {
gchar *out = conv_codeset_strdup(value,
conv_get_locale_charset_str_no_utf8(),
CS_INTERNAL);
if (out)
ADDRITEM_NAME(person) = mgu_replace_string( ADDRITEM_NAME(person), out );
g_free(out);
}
2001-09-02 01:48:06 +02:00
}
2003-03-20 00:16:26 +01:00
/**
* Specify external ID for person object.
* \param person Person object.
* \param value ID.
*/
2001-09-02 01:48:06 +02:00
void addritem_person_set_external_id( ItemPerson *person, const gchar *value ) {
person->externalID = mgu_replace_string( person->externalID, value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify value of open indicator for person object. This is typically used to
* simplify open/close folders in the address book GUI.
* \param person Person object.
* \param value Value for indicator. Set to <i>TRUE</i> if opened.
*/
2001-09-02 01:48:06 +02:00
void addritem_person_set_opened( ItemPerson *person, const gboolean value ) {
person->isOpened = value;
}
2003-03-20 00:16:26 +01:00
/**
2002-08-06 07:52:56 +02:00
* Test whether person's data is empty.
2003-03-20 00:16:26 +01:00
* \param person Person to test.
* \return <i>TRUE</i> if empty.
2002-08-06 07:52:56 +02:00
*/
gboolean addritem_person_empty( ItemPerson *person ) {
gchar *t;
if( person == NULL ) return FALSE;
t = ADDRITEM_NAME(person);
if( t != NULL && strlen( t ) > 0 ) return FALSE;
t = person->firstName;
if( t != NULL && strlen( t ) > 0 ) return FALSE;
t = person->lastName;
if( t != NULL && strlen( t ) > 0 ) return FALSE;
t = person->nickName;
if( t != NULL && strlen( t ) > 0 ) return FALSE;
if( person->listEMail != NULL ) return FALSE;
if( person->listAttrib != NULL ) return FALSE;
return TRUE;
}
2003-03-20 00:16:26 +01:00
/**
2002-08-06 07:52:56 +02:00
* Free linked list of item addresses; both addresses and the list are freed.
* It is assumed that addresses are *NOT* contained within some other
* container.
2003-03-20 00:16:26 +01:00
* \param list List of addresses to be freed.
2002-08-06 07:52:56 +02:00
*/
2001-09-02 01:48:06 +02:00
void addritem_free_list_email( GList *list ) {
GList *node = list;
while( node ) {
2002-08-06 07:52:56 +02:00
ItemEMail *email = node->data;
addritem_free_item_email( email );
2001-09-02 01:48:06 +02:00
node->data = NULL;
node = g_list_next( node );
}
g_list_free( list );
2002-08-06 07:52:56 +02:00
list = NULL;
2001-09-02 01:48:06 +02:00
}
2003-03-20 00:16:26 +01:00
/**
* Free linked list of attributes; both attributes and the list are freed.
* It is assumed that attributes are *NOT* contained within some other
* container.
* \param list List of attributes to be freed.
*/
2001-09-02 01:48:06 +02:00
void addritem_free_list_attribute( GList *list ) {
GList *node = list;
while( node ) {
addritem_free_attribute( node->data );
node->data = NULL;
node = g_list_next( node );
}
g_list_free( list );
}
2003-03-20 00:16:26 +01:00
/**
* Free address person object.
* \param person Person object to free.
*/
2001-09-02 01:48:06 +02:00
void addritem_free_item_person( ItemPerson *person ) {
g_return_if_fail( person != NULL );
/* Free internal stuff */
g_free( ADDRITEM_ID(person) );
g_free( ADDRITEM_NAME(person) );
g_free( person->firstName );
g_free( person->lastName );
g_free( person->nickName );
g_free( person->externalID );
2002-08-06 07:52:56 +02:00
g_list_free( person->listEMail );
2001-09-02 01:48:06 +02:00
addritem_free_list_attribute( person->listAttrib );
ADDRITEM_OBJECT(person)->type = ITEMTYPE_NONE;
ADDRITEM_ID(person) = NULL;
ADDRITEM_NAME(person) = NULL;
ADDRITEM_PARENT(person) = NULL;
ADDRITEM_SUBTYPE(person) = 0;
person->firstName = NULL;
person->lastName = NULL;
person->nickName = NULL;
person->externalID = NULL;
person->listEMail = NULL;
person->listAttrib = NULL;
g_free( person );
}
2003-03-20 00:16:26 +01:00
/**
* Print E-Mail address object for debug.
* \param item Item to print.
* \param stream Output stream.
*/
2001-09-02 01:48:06 +02:00
void addritem_print_item_email( ItemEMail *item, FILE *stream ) {
g_return_if_fail( item != NULL );
fprintf( stream, "\t\tt/id: %d : '%s'\n", ADDRITEM_TYPE(item), ADDRITEM_ID(item) );
fprintf( stream, "\t\tsubty: %d\n", ADDRITEM_SUBTYPE(item) );
fprintf( stream, "\t\talis: '%s'\n", ADDRITEM_NAME(item) );
fprintf( stream, "\t\taddr: '%s'\n", item->address );
fprintf( stream, "\t\trems: '%s'\n", item->remarks );
fprintf( stream, "\t\t---\n" );
}
2003-03-20 00:16:26 +01:00
/**
* Print user attribute object for debug.
* \param item Attribute to print.
* \param stream Output stream.
*/
2001-09-02 01:48:06 +02:00
void addritem_print_attribute( UserAttribute *item, FILE *stream ) {
g_return_if_fail( item != NULL );
fprintf( stream, "\t\tuid : '%s'\n", item->uid );
fprintf( stream, "\t\tname : '%s'\n", item->name );
fprintf( stream, "\t\tvalue: '%s'\n", item->value );
fprintf( stream, "\t\t---\n" );
}
2003-03-20 00:16:26 +01:00
/**
* Print person item for debug.
* \param person Person to print.
* \param stream Output stream.
*/
2001-09-02 01:48:06 +02:00
void addritem_print_item_person( ItemPerson *person, FILE *stream ) {
GList *node;
g_return_if_fail( person != NULL );
fprintf( stream, "Person:\n" );
fprintf( stream, "\tt/uid: %d : '%s'\n", ADDRITEM_TYPE(person), ADDRITEM_ID(person) );
fprintf( stream, "\tsubty: %d\n", ADDRITEM_SUBTYPE(person) );
fprintf( stream, "\tcommn: '%s'\n", ADDRITEM_NAME(person) );
fprintf( stream, "\tfirst: '%s'\n", person->firstName );
fprintf( stream, "\tlast : '%s'\n", person->lastName );
fprintf( stream, "\tnick : '%s'\n", person->nickName );
fprintf( stream, "\textID: '%s'\n", person->externalID );
fprintf( stream, "\teMail:\n" );
fprintf( stream, "\t---\n" );
node = person->listEMail;
while( node ) {
addritem_print_item_email( node->data, stream );
node = g_list_next( node );
}
fprintf( stream, "\tuAttr:\n" );
fprintf( stream, "\t---\n" );
node = person->listAttrib;
while( node ) {
addritem_print_attribute( node->data, stream );
node = g_list_next( node );
}
fprintf( stream, "\t===\n" );
}
2003-03-20 00:16:26 +01:00
/**
* Add E-Mail address object to person.
* \param person Person.
* \param email E-Mail object to add.
* \return <i>TRUE</i> if E-Mail added.
*/
2001-09-02 01:48:06 +02:00
gboolean addritem_person_add_email( ItemPerson *person, ItemEMail *email ) {
GList *node;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( person != NULL, FALSE );
g_return_val_if_fail( email != NULL, FALSE );
2001-09-02 01:48:06 +02:00
node = person->listEMail;
while( node ) {
if( node->data == email ) return FALSE;
node = g_list_next( node );
}
person->listEMail = g_list_append( person->listEMail, email );
ADDRITEM_PARENT(email) = ADDRITEM_OBJECT(person);
return TRUE;
}
2003-03-20 00:16:26 +01:00
/**
* Return email object with specified ID for specified person.
* \param person Person object.
* \param eid EMail ID.
* \return EMail object, or <i>NULL</i> if not found.
*/
2001-09-02 01:48:06 +02:00
ItemEMail *addritem_person_get_email( ItemPerson *person, const gchar *eid ) {
ItemEMail *email = NULL;
GList *node;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( person != NULL, NULL );
2001-09-02 01:48:06 +02:00
if( eid == NULL || *eid == '\0' ) return NULL;
2001-09-27 10:16:30 +02:00
/* Look for email */
2001-09-02 01:48:06 +02:00
node = person->listEMail;
while( node ) {
AddrItemObject *objE = node->data;
gchar *ide = ADDRITEM_ID(objE);
if( ide ) {
if( strcmp( ide, eid ) == 0 ) {
email = ( ItemEMail * ) objE;
}
}
node = g_list_next( node );
}
return email;
}
2003-03-20 00:16:26 +01:00
/**
* Remove email address with specified ID for specified person.
* \param person Person object.
* \param eid EMail ID.
* \return EMail object, or <i>NULL</i> if not found. Note that object should
* still be freed after calling this function.
*/
2001-09-02 01:48:06 +02:00
ItemEMail *addritem_person_remove_email_id( ItemPerson *person, const gchar *eid ) {
ItemEMail *email = NULL;
GList *node;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( person != NULL, NULL );
2001-09-02 01:48:06 +02:00
if( eid == NULL || *eid == '\0' ) return NULL;
2001-09-27 10:16:30 +02:00
/* Look for email */
2001-09-02 01:48:06 +02:00
node = person->listEMail;
while( node ) {
AddrItemObject *objE = node->data;
gchar *ide = ADDRITEM_ID(objE);
if( ide ) {
if( strcmp( ide, eid ) == 0 ) {
email = ( ItemEMail * ) objE;
}
}
node = g_list_next( node );
}
if( email ) {
2001-09-27 10:16:30 +02:00
/* Remove email from person's address list */
2001-09-02 01:48:06 +02:00
if( person->listEMail ) {
person->listEMail = g_list_remove( person->listEMail, email );
}
2001-09-27 10:16:30 +02:00
/* Unlink reference to person. */
2001-09-02 01:48:06 +02:00
ADDRITEM_PARENT(email) = NULL;
}
return email;
}
2003-03-20 00:16:26 +01:00
/**
* Remove email address for specified person.
* \param person Person.
* \param email EMail to remove.
* \return EMail object, or <i>NULL</i> if not found. Note that object should
* still be freed after calling this method.
*/
2001-09-02 01:48:06 +02:00
ItemEMail *addritem_person_remove_email( ItemPerson *person, ItemEMail *email ) {
gboolean found = FALSE;
GList *node;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( person != NULL, NULL );
2001-09-02 01:48:06 +02:00
if( email == NULL ) return NULL;
2001-09-27 10:16:30 +02:00
/* Look for email */
2001-09-02 01:48:06 +02:00
node = person->listEMail;
while( node ) {
if( node-> data == email ) {
found = TRUE;
break;
}
node = g_list_next( node );
}
if( found ) {
2001-09-27 10:16:30 +02:00
/* Remove email from person's address list */
2001-09-02 01:48:06 +02:00
if( person->listEMail ) {
person->listEMail = g_list_remove( person->listEMail, email );
}
2001-09-27 10:16:30 +02:00
/* Unlink reference to person. */
2001-09-02 01:48:06 +02:00
ADDRITEM_PARENT(email) = NULL;
return email;
}
return NULL;
}
2003-03-20 00:16:26 +01:00
/**
* Add user attribute to specified person.
* \param person Person.
* \param attrib Attribute to add.
* \return <i>TRUE</i> if item added.
*/
void addritem_person_add_attribute(
ItemPerson *person, UserAttribute *attrib )
{
2001-09-02 01:48:06 +02:00
g_return_if_fail( person != NULL );
person->listAttrib = g_list_append( person->listAttrib, attrib );
}
2003-03-20 00:16:26 +01:00
/**
* Return attribute with specified ID for person.
* \param person Person object.
* \param aid Attribute ID.
* \return Reference to UserAttribute object, or <i>NULL</i> if not found.
*/
UserAttribute *addritem_person_get_attribute(
ItemPerson *person, const gchar *aid )
{
2001-09-02 01:48:06 +02:00
UserAttribute *attrib = NULL;
GList *node;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( person != NULL, NULL );
2001-09-02 01:48:06 +02:00
if( aid == NULL || *aid == '\0' ) return NULL;
2001-09-27 10:16:30 +02:00
/* Look for attribute */
2001-09-02 01:48:06 +02:00
node = person->listAttrib;
while( node ) {
UserAttribute *attr = node->data;
gchar *ida = attr->uid;
if( ida ) {
if( strcmp( ida, aid ) == 0 ) {
attrib = attr;
}
}
node = g_list_next( node );
}
return attrib;
}
2003-03-20 00:16:26 +01:00
/**
* Remove attribute with specified ID from person.
* \param person Person object.
* \param aid Attribute ID to remove.
* \return UserAttribute object, or <i>NULL</i> if not found. Note that
* attribute object should still be freed after calling this method.
*/
UserAttribute *addritem_person_remove_attrib_id(
ItemPerson *person, const gchar *aid )
{
2001-09-02 01:48:06 +02:00
UserAttribute *attrib = NULL;
GList *node;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( person != NULL, NULL );
2001-09-02 01:48:06 +02:00
if( aid == NULL || *aid == '\0' ) return NULL;
2001-09-27 10:16:30 +02:00
/* Look for attribute */
2001-09-02 01:48:06 +02:00
node = person->listAttrib;
while( node ) {
UserAttribute *attr = node->data;
gchar *ida = attr->uid;
if( ida ) {
if( strcmp( ida, aid ) == 0 ) {
attrib = attr;
}
}
node = g_list_next( node );
}
2001-09-27 10:16:30 +02:00
/* Remove email from person's address list */
2001-09-02 01:48:06 +02:00
if( person->listAttrib ) {
person->listAttrib = g_list_remove( person->listAttrib, attrib );
}
return attrib;
}
2003-03-20 00:16:26 +01:00
/**
* Remove attribute from person.
* \param person Person.
* \param attrib Attribute to remove.
* \return UserAttribute object to remove. Note that attribute object should
* still be freed.
*/
UserAttribute *addritem_person_remove_attribute(
ItemPerson *person, UserAttribute *attrib )
{
2001-09-02 01:48:06 +02:00
gboolean found = FALSE;
GList *node;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( person != NULL, NULL );
2001-09-02 01:48:06 +02:00
if( attrib == NULL ) return NULL;
2001-09-27 10:16:30 +02:00
/* Look for attribute */
2001-09-02 01:48:06 +02:00
node = person->listAttrib;
while( node ) {
if( node-> data == attrib ) {
found = TRUE;
break;
}
node = g_list_next( node );
}
if( found ) {
2001-09-27 10:16:30 +02:00
/* Remove attribute */
2001-09-02 01:48:06 +02:00
if( person->listAttrib ) {
person->listAttrib = g_list_remove( person->listAttrib, attrib );
}
}
return attrib;
}
2003-03-20 00:16:26 +01:00
/**
* Create new address book group object.
* \return Initialized group object.
*/
2001-09-02 01:48:06 +02:00
ItemGroup *addritem_create_item_group( void ) {
ItemGroup *group;
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
group = g_new0( ItemGroup, 1 );
ADDRITEM_TYPE(group) = ITEMTYPE_GROUP;
ADDRITEM_ID(group) = NULL;
ADDRITEM_NAME(group) = NULL;
ADDRITEM_PARENT(group) = NULL;
ADDRITEM_SUBTYPE(group) = 0;
group->remarks = NULL;
group->listEMail = NULL;
return group;
}
2003-03-20 00:16:26 +01:00
/**
* Copy (deep copy) address book group.
* \param item Group to copy.
* \return Copy of the group object, or <i>NULL</i> if null argument supplied.
*/
ItemGroup *addritem_copy_item_group( ItemGroup *item ) {
ItemGroup *itemNew;
itemNew = g_new0( ItemGroup, 1 );
if( item ) {
itemNew = addritem_create_item_group();
ADDRITEM_NAME(itemNew) = g_strdup( ADDRITEM_NAME(item) );
itemNew->remarks = g_strdup( item->remarks );
}
return itemNew;
}
2003-03-20 00:16:26 +01:00
/**
* Specify ID to be used for group.
* \param group Group object.
* \param value ID of group.
*/
2001-09-02 01:48:06 +02:00
void addritem_group_set_id( ItemGroup *group, const gchar *value ) {
ADDRITEM_ID(group) = mgu_replace_string( ADDRITEM_ID(group), value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify name to be used for group.
* \param group Group object.
* \param value Name of group.
*/
2001-09-02 01:48:06 +02:00
void addritem_group_set_name( ItemGroup *group, const gchar *value ) {
ADDRITEM_NAME(group) = mgu_replace_string( ADDRITEM_NAME(group), value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify remarks to be used for group.
* \param group Group object.
* \param value Remarks for group.
*/
2001-09-02 01:48:06 +02:00
void addritem_group_set_remarks( ItemGroup *group, const gchar *value ) {
group->remarks = mgu_replace_string( group->remarks, value );
}
2003-03-20 00:16:26 +01:00
/**
* Free address group object.
* \param group Group to free.
*/
2001-09-02 01:48:06 +02:00
void addritem_free_item_group( ItemGroup *group ) {
g_return_if_fail( group != NULL );
/* Free internal stuff */
g_free( ADDRITEM_ID(group) );
g_free( ADDRITEM_NAME(group) );
g_free( group->remarks );
mgu_clear_list( group->listEMail );
g_list_free( group->listEMail );
ADDRITEM_TYPE(group) = ITEMTYPE_NONE;
ADDRITEM_ID(group) = NULL;
ADDRITEM_NAME(group) = NULL;
ADDRITEM_PARENT(group) = NULL;
ADDRITEM_SUBTYPE(group) = 0;
group->remarks = NULL;
group->listEMail = NULL;
g_free( group );
}
2003-03-20 00:16:26 +01:00
/**
* Add EMail address to group. Note that a reference to an E-Mail item is
* added to a group. A person object is the only container that for an
* address.
* \param group Group.
* \param email E-Mail object.
* \return <i>TRUE</i> if email item added.
*/
2001-09-02 01:48:06 +02:00
gboolean addritem_group_add_email( ItemGroup *group, ItemEMail *email ) {
GList *node;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( group != NULL, FALSE );
g_return_val_if_fail( email != NULL, FALSE );
2001-09-02 01:48:06 +02:00
node = group->listEMail;
while( node ) {
if( node->data == email ) return FALSE;
node = g_list_next( node );
}
group->listEMail = g_list_append( group->listEMail, email );
return TRUE;
}
2003-03-20 00:16:26 +01:00
/**
* Remove email address object for specified group.
* \param group Group from which to remove address.
* \param email EMail to remove
* \return EMail object, or <i>NULL if email not found in group. Note that
* this object is referenced (linked) to a group and should *NOT*
* be freed. An E-Mail object object should only be freed after
* removing from a person.
*/
2001-09-02 01:48:06 +02:00
ItemEMail *addritem_group_remove_email( ItemGroup *group, ItemEMail *email ) {
if( group && email ) {
GList *node = group->listEMail;
while( node ) {
if( node->data == email ) {
group->listEMail = g_list_remove( group->listEMail, email );
return email;
}
node = g_list_next( node );
}
}
return NULL;
}
/**
* Remove person object for specified group.
* \param group Group from which to remove address.
* \param email EMail to remove
* \return EMail object, or <i>NULL if email not found in group. Note that
* this object is referenced (linked) to a group and should *NOT*
* be freed. An E-Mail object object should only be freed after
* removing from a person.
*/
ItemPerson *addritem_folder_remove_person( ItemFolder *group, ItemPerson *person ) {
if( group && person ) {
GList *node = group->listPerson;
while( node ) {
if( node->data == person ) {
group->listPerson = g_list_remove( group->listPerson, person );
return person;
}
node = g_list_next( node );
}
}
return NULL;
}
2003-03-20 00:16:26 +01:00
/**
* Remove email address of specified ID for specified group.
* \param group Group from which to remove address.
* \param eid EMail ID.
* \return EMail object, or <i>NULL</i> if email not found in group. Note that
* this object is referenced (linked) to a group and should *NOT* be
* freed. An E-Mail object should only be freed after removing from a
* person.
*/
2001-09-02 01:48:06 +02:00
ItemEMail *addritem_group_remove_email_id( ItemGroup *group, const gchar *eid ) {
if( group ) {
GList *node = group->listEMail;
while( node ) {
ItemEMail *email = ( ItemEMail * ) node->data;
if( strcmp( ADDRITEM_ID( email ), eid ) == 0 ) {
group->listEMail = g_list_remove( group->listEMail, email );
return email;
}
node = g_list_next( node );
}
}
return NULL;
}
2003-03-20 00:16:26 +01:00
/**
* Print address group item for debug.
* \param group Group to print.
* \param stream Output stream.
*/
2001-09-02 01:48:06 +02:00
void addritem_print_item_group( ItemGroup *group, FILE *stream ) {
GList *node;
ItemPerson *person;
ItemEMail *item;
g_return_if_fail( group != NULL );
fprintf( stream, "Group:\n" );
fprintf( stream, "\tt/u: %d : '%s'\n", ADDRITEM_TYPE(group), ADDRITEM_ID(group) );
fprintf( stream, "\tsub: %d\n", ADDRITEM_SUBTYPE(group) );
fprintf( stream, "\tgrp: '%s'\n", ADDRITEM_NAME(group) );
fprintf( stream, "\trem: '%s'\n", group->remarks );
fprintf( stream, "\t---\n" );
node = group->listEMail;
while( node ) {
item = node->data;
person = ( ItemPerson * ) ADDRITEM_PARENT(item);
if( person ) {
fprintf( stream, "\t\tpid : '%s'\n", ADDRITEM_ID(person) );
fprintf( stream, "\t\tcomn: '%s'\n", ADDRITEM_NAME(person) );
}
else {
fprintf( stream, "\t\tpid : ???\n" );
fprintf( stream, "\t\tcomn: ???\n" );
}
addritem_print_item_email( item, stream );
node = g_list_next( node );
}
fprintf( stream, "\t***\n" );
}
2003-06-21 08:23:00 +02:00
/**
* Create new address folder.
* \return Initialized address folder object.
*/
2001-09-02 01:48:06 +02:00
ItemFolder *addritem_create_item_folder( void ) {
ItemFolder *folder;
folder = g_new0( ItemFolder, 1 );
ADDRITEM_TYPE(folder) = ITEMTYPE_FOLDER;
ADDRITEM_ID(folder) = NULL;
ADDRITEM_NAME(folder) = NULL;
ADDRITEM_PARENT(folder) = NULL;
ADDRITEM_SUBTYPE(folder) = 0;
folder->remarks = NULL;
folder->isRoot = FALSE;
folder->listItems = NULL;
folder->listFolder = NULL;
folder->listPerson = NULL;
folder->listGroup = NULL;
2003-06-21 08:23:00 +02:00
folder->folderType = ADDRFOLDER_NONE;
folder->folderData = NULL;
2003-09-07 21:28:56 +02:00
folder->isHidden = FALSE;
2001-09-02 01:48:06 +02:00
return folder;
}
2003-06-21 08:23:00 +02:00
/**
* Copy address book folder. Note that only the folder and not its contents are
* copied.
* \param item Folder to copy.
* \return A copy of the folder, or <i>NULL</i> if null argument supplied.
*/
ItemFolder *addritem_copy_item_folder( ItemFolder *item ) {
ItemFolder *itemNew;
itemNew = g_new0( ItemFolder, 1 );
if( item ) {
itemNew = addritem_create_item_folder();
ADDRITEM_NAME(itemNew) = g_strdup( ADDRITEM_NAME(item) );
2003-06-21 08:23:00 +02:00
itemNew->folderType = item->folderType;
}
return itemNew;
}
2003-03-20 00:16:26 +01:00
/**
* Specify ID to be used for folder.
* \param folder Folder.
* \param value ID.
*/
2001-09-02 01:48:06 +02:00
void addritem_folder_set_id( ItemFolder *folder, const gchar *value ) {
ADDRITEM_ID(folder) = mgu_replace_string( ADDRITEM_ID(folder), value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify name to be used for folder.
* \param folder Folder.
* \param value Name.
*/
2001-09-02 01:48:06 +02:00
void addritem_folder_set_name( ItemFolder *folder, const gchar *value ) {
ADDRITEM_NAME(folder) = mgu_replace_string( ADDRITEM_NAME(folder), value );
}
2003-03-20 00:16:26 +01:00
/**
* Specify remarks to be used for folder.
* \param folder Folder.
* \param value Remarks.
*/
2001-09-02 01:48:06 +02:00
void addritem_folder_set_remarks( ItemFolder *folder, const gchar *value ) {
folder->remarks = mgu_replace_string( folder->remarks, value );
}
2003-09-07 21:28:56 +02:00
/**
* Specify visibility of folder.
* \param folder Folder.
* \param value Set to <code>TRUE</code> to hide folder.
*/
void addritem_folder_set_hidden( ItemFolder *folder, const gboolean value ) {
folder->isHidden = value;
}
2003-06-21 08:23:00 +02:00
/**
* Free address folder. Note: this does not free up the lists of children
* (folders, groups and person). This should be done prior to calling this
* function.
* \param folder Folder to free.
*/
2001-09-02 01:48:06 +02:00
void addritem_free_item_folder( ItemFolder *folder ) {
g_return_if_fail( folder != NULL );
2001-09-27 10:16:30 +02:00
/* Free internal stuff */
2001-09-02 01:48:06 +02:00
g_free( ADDRITEM_ID(folder) );
g_free( ADDRITEM_NAME(folder) );
g_free( folder->remarks );
mgu_clear_list( folder->listItems );
g_list_free( folder->listItems );
ADDRITEM_TYPE(folder) = ITEMTYPE_NONE;
ADDRITEM_ID(folder) = NULL;
ADDRITEM_NAME(folder) = NULL;
ADDRITEM_PARENT(folder) = NULL;
ADDRITEM_SUBTYPE(folder) = 0;
folder->isRoot = FALSE;
folder->remarks = NULL;
folder->listItems = NULL;
folder->listFolder = NULL;
folder->listGroup = NULL;
folder->listPerson = NULL;
2003-06-21 08:23:00 +02:00
folder->folderType = ADDRFOLDER_NONE;
folder->folderData = NULL;
2003-09-07 21:28:56 +02:00
folder->isHidden = FALSE;
2001-09-02 01:48:06 +02:00
g_free( folder );
}
2003-03-20 00:16:26 +01:00
/**
* Free up folders recursively. Note: this only frees up the lists of
* children and *NOT* the children objects (folders, groups and person).
* This should be done prior to calling this function.
* \param parent Parent folder object to be processed.
*/
2001-09-02 01:48:06 +02:00
void addritem_free_item_folder_recurse( ItemFolder *parent ) {
GList *node = parent->listFolder;
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
while( node ) {
ItemFolder *folder = node->data;
addritem_free_item_folder_recurse( folder );
node = g_list_next( node );
}
g_list_free( parent->listPerson );
g_list_free( parent->listGroup );
g_list_free( parent->listFolder );
parent->listPerson = NULL;
parent->listGroup = NULL;
parent->listFolder = NULL;
}
2003-03-20 00:16:26 +01:00
/**
* Free up list of person objects contained in specified folder.
* \param folder Folder to process.
*/
2001-09-02 01:48:06 +02:00
void addritem_folder_free_person( ItemFolder *folder ) {
GList *node;
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
g_return_if_fail( folder != NULL );
2001-09-27 10:16:30 +02:00
/* Free up folder of persons. */
2001-09-02 01:48:06 +02:00
node = folder->listPerson;
while( node ) {
ItemPerson *person = node->data;
addritem_free_item_person( person );
person = NULL;
node = g_list_next( node );
}
}
2003-03-20 00:16:26 +01:00
/**
* Add person into folder.
* \param folder Folder.
* \param item Person to add.
* \return <i>TRUE</i> if person added.
*/
2001-09-02 01:48:06 +02:00
gboolean addritem_folder_add_person( ItemFolder *folder, ItemPerson *item ) {
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( folder != NULL, FALSE );
g_return_val_if_fail( item != NULL, FALSE );
2001-09-02 01:48:06 +02:00
folder->listPerson = g_list_append( folder->listPerson, item );
ADDRITEM_PARENT(item) = ADDRITEM_OBJECT(folder);
return TRUE;
}
2003-03-20 00:16:26 +01:00
/**
* Add folder into folder.
* \param folder Folder.
* \param item Folder to add.
* \return <i>TRUE</i> if folder added.
*/
2001-09-02 01:48:06 +02:00
gboolean addritem_folder_add_folder( ItemFolder *folder, ItemFolder *item ) {
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( folder != NULL, FALSE );
g_return_val_if_fail( item != NULL, FALSE );
2001-09-02 01:48:06 +02:00
folder->listFolder = g_list_append( folder->listFolder, item );
ADDRITEM_PARENT(item) = ADDRITEM_OBJECT(folder);
return TRUE;
}
2003-03-20 00:16:26 +01:00
/**
* Add group into folder.
* \param folder Folder.
* \param item Group to add.
* \return <i>TRUE</i> if group added.
*/
2001-09-02 01:48:06 +02:00
gboolean addritem_folder_add_group( ItemFolder *folder, ItemGroup *item ) {
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( folder != NULL, FALSE );
g_return_val_if_fail( item != NULL, FALSE );
2001-09-02 01:48:06 +02:00
folder->listGroup = g_list_append( folder->listGroup, item );
ADDRITEM_PARENT(item) = ADDRITEM_OBJECT(folder);
return TRUE;
}
2003-03-20 00:16:26 +01:00
/**
* Print address folder item contents for debug.
* \param folder Folder to process.
* \param stream Output stream.
*/
2001-09-02 01:48:06 +02:00
void addritem_print_item_folder( ItemFolder *folder, FILE *stream ) {
GList *node;
2001-09-27 10:16:30 +02:00
/* ItemPerson *person; */
2001-09-02 01:48:06 +02:00
ItemFolder *parent;
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
g_return_if_fail( folder != NULL );
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
fprintf( stream, "Folder:\n" );
fprintf( stream, "\tt/u: %d : '%s'\n", ADDRITEM_TYPE(folder), ADDRITEM_ID(folder) );
fprintf( stream, "\tsub: %d\n", ADDRITEM_SUBTYPE(folder) );
fprintf( stream, "\tnam: '%s'\n", ADDRITEM_NAME(folder) );
fprintf( stream, "\trem: '%s'\n", folder->remarks );
2003-06-21 08:23:00 +02:00
fprintf( stream, "\ttyp: %d\n", folder->folderType );
2003-09-07 21:28:56 +02:00
fprintf( stream, "\thid: %s\n", folder->isHidden ? "hidden" : "visible" );
2001-09-02 01:48:06 +02:00
fprintf( stream, "\t---\n" );
parent = ( ItemFolder * ) ADDRITEM_PARENT(folder);
if( parent ) {
fprintf( stream, "\tpar: %s : %s\n", ADDRITEM_ID(parent), ADDRITEM_NAME(parent) );
}
else {
fprintf( stream, "\tpar: NULL\n" );
}
node = folder->listFolder;
while( node ) {
AddrItemObject *aio = node->data;
if( aio ) {
if( aio->type == ITEMTYPE_FOLDER ) {
ItemFolder *item = ( ItemFolder * ) aio;
addritem_print_item_folder( item, stream );
}
}
else {
fprintf( stream, "\t\tpid : ???\n" );
}
node = g_list_next( node );
}
node = folder->listPerson;
while( node ) {
AddrItemObject *aio = node->data;
if( aio ) {
if( aio->type == ITEMTYPE_PERSON ) {
ItemPerson *item = ( ItemPerson * ) aio;
addritem_print_item_person( item, stream );
}
}
else {
fprintf( stream, "\t\tpid : ???\n" );
}
node = g_list_next( node );
}
node = folder->listGroup;
while( node ) {
AddrItemObject *aio = node->data;
if( aio ) {
if( aio->type == ITEMTYPE_GROUP ) {
ItemGroup *item = ( ItemGroup * ) aio;
addritem_print_item_group( item, stream );
}
}
else {
fprintf( stream, "\t\tpid : ???\n" );
}
node = g_list_next( node );
}
fprintf( stream, "\t###\n" );
}
2003-03-20 00:16:26 +01:00
/**
* Print address item for debug.
* \param aio Address item to format.
* \param stream Output stream.
*/
void addritem_print_item( AddrItemObject *aio, FILE *stream ) {
g_return_if_fail( aio != NULL );
if( aio->type == ITEMTYPE_PERSON ) {
ItemPerson *item = ( ItemPerson * ) aio;
addritem_print_item_person( item, stream );
}
else if( aio->type == ITEMTYPE_EMAIL ) {
ItemEMail *item = ( ItemEMail * ) aio;
addritem_print_item_email( item, stream );
}
else if( aio->type == ITEMTYPE_GROUP ) {
ItemGroup *item = ( ItemGroup * ) aio;
addritem_print_item_group( item, stream );
}
else if( aio->type == ITEMTYPE_FOLDER ) {
ItemFolder *item = ( ItemFolder * ) aio;
addritem_print_item_folder( item, stream );
}
}
2003-03-20 00:16:26 +01:00
/**
* Return link list of persons for specified folder. Note that the list contains
* references to items and should be g_free() when done. Do *NOT* attempt to use the
* addritem_free_xxx() functions... this will destroy the addressbook data!
*
* \param folder Folder to process.
* \return List of items, or <i>NULL</i> if none.
*/
2001-09-02 01:48:06 +02:00
GList *addritem_folder_get_person_list( ItemFolder *folder ) {
GList *list = NULL;
GList *node = NULL;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( folder != NULL, NULL );
2001-09-02 01:48:06 +02:00
node = folder->listPerson;
while( node ) {
ItemPerson *person = node->data;
2001-09-06 12:24:20 +02:00
list = g_list_append( list, person );
2001-09-02 01:48:06 +02:00
node = g_list_next( node );
}
return list;
}
2003-03-20 00:16:26 +01:00
/**
* Return link list of groups for specified folder. Note that the list contains
* references to items and should be g_free() when done. Do *NOT* attempt to use the
* addritem_free_xxx() functions... this will destroy the addressbook data!
*
* \param folder Folder to process.
* \return List of items, or <i>NULL</i> if none.
*/
2001-09-02 01:48:06 +02:00
GList *addritem_folder_get_group_list( ItemFolder *folder ) {
GList *list = NULL;
GList *node = NULL;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( folder != NULL, NULL );
2001-09-02 01:48:06 +02:00
node = folder->listGroup;
while( node ) {
ItemGroup *group = node->data;
2001-09-06 12:24:20 +02:00
list = g_list_append( list, group );
2001-09-02 01:48:06 +02:00
node = g_list_next( node );
}
return list;
}
2003-03-20 00:16:26 +01:00
/**
* Move person's email item.
* \param person Person.
* \param itemMove Item to move.
* \param itemTarget Target item before which to move item.
* \return Reference to item that was moved, or <i>NULL</i> if null arguments
* supplied.
*/
2001-09-02 01:48:06 +02:00
2003-03-20 00:16:26 +01:00
ItemEMail *addritem_move_email_before(
ItemPerson *person, ItemEMail *itemMove, ItemEMail *itemTarget )
{
2001-09-02 01:48:06 +02:00
gint posT, posM;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( person != NULL, NULL );
2001-09-02 01:48:06 +02:00
if( itemTarget == NULL ) return NULL;
if( itemMove == NULL ) return NULL;
if( itemMove == itemTarget ) return itemMove;
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
posT = g_list_index( person->listEMail, itemTarget );
if( posT < 0 ) return NULL;
posM = g_list_index( person->listEMail, itemMove );
if( posM < 0 ) return NULL;
person->listEMail = g_list_remove( person->listEMail, itemMove );
person->listEMail = g_list_insert( person->listEMail, itemMove, posT );
return itemMove;
}
2003-03-20 00:16:26 +01:00
/**
* Move person's email item.
* \param person Person.
* \param itemMove Item to move.
* \param itemTarget Target item after which to move item.
* \return Reference to item that was moved, or <i>NULL</i> if null arguments
* supplied.
*/
ItemEMail *addritem_move_email_after(
ItemPerson *person, ItemEMail *itemMove, ItemEMail *itemTarget )
{
2001-09-02 01:48:06 +02:00
gint posT, posM;
2001-09-06 12:24:20 +02:00
g_return_val_if_fail( person != NULL, NULL );
2001-09-02 01:48:06 +02:00
if( itemTarget == NULL ) return NULL;
if( itemMove == NULL ) return NULL;
if( itemMove == itemTarget ) return itemMove;
2001-09-06 12:24:20 +02:00
2001-09-02 01:48:06 +02:00
posT = g_list_index( person->listEMail, itemTarget );
if( posT < 0 ) return NULL;
posM = g_list_index( person->listEMail, itemMove );
if( posM < 0 ) return NULL;
person->listEMail = g_list_remove( person->listEMail, itemMove );
person->listEMail = g_list_insert( person->listEMail, itemMove, 1+posT );
return itemMove;
}
2002-04-08 05:51:28 +02:00
/**
* Parse first and last names for person from common name.
2003-03-20 00:16:26 +01:00
* \param person Person to process.
2002-04-08 05:51:28 +02:00
*/
void addritem_parse_first_last( ItemPerson *person ) {
gchar *name;
gchar *fName, *lName;
gchar *p;
gint len, i;
g_return_if_fail( person != NULL );
name = ADDRITEM_NAME(person);
if( name == NULL ) return;
fName = NULL;
lName = NULL;
p = strchr( name, ',' );
if( p ) {
len = ( size_t ) ( p - name );
lName = g_strndup( name, len );
fName = g_strdup( p + 1 );
}
else {
/* Other way around */
i = strlen( name );
while( i >= 0 ) {
if( name[i] == ' ' ) {
fName = g_strndup( name, i );
lName = g_strdup( &name[i] );
break;
}
i--;
}
if( fName == NULL ) {
fName = g_strdup( name );
}
}
if( person->firstName ) {
g_free( person->firstName );
}
person->firstName = fName;
if( person->firstName )
g_strstrip( person->firstName );
if( person->lastName ) {
g_free( person->lastName );
}
person->lastName = lName;
if( person->lastName )
g_strstrip( person->lastName );
}
2003-03-20 00:16:26 +01:00
/**
2002-05-06 08:27:11 +02:00
* Build a path of all ancestor folders for specified folder.
2003-03-20 00:16:26 +01:00
* \param folder Folder.
* \param seq Path sequence, FALSE top down, TRUE bottom up.
* \return List of folders from the top down.
2002-05-06 08:27:11 +02:00
*/
GList *addritem_folder_path( const ItemFolder *folder, const gboolean seq ) {
GList *list;
AddrItemObject *item;
list = NULL;
item = ( AddrItemObject * ) folder;
if( seq ) {
while( item ) {
list = g_list_prepend( list, item );
item = ADDRITEM_PARENT( item );
}
}
else {
while( item ) {
list = g_list_append( list, item );
item = ADDRITEM_PARENT( item );
}
}
return list;
}
2003-06-21 08:23:00 +02:00
/**
* Format E-Mail address.
* \param email EMail item to format.
* \return Formatted string. Should be freed after use.
*/
gchar *addritem_format_email( ItemEMail *email ) {
gchar *address;
gchar *name;
ItemPerson *person;
address = NULL;
name = NULL;
if( ADDRITEM_NAME( email ) ) {
if( strlen( ADDRITEM_NAME( email ) ) ) {
name = ADDRITEM_NAME( email );
}
}
if( ! name ) {
person = ( ItemPerson * ) ADDRITEM_PARENT( email );
name = ADDRITEM_NAME( person );
}
if( name ) {
if( strchr_with_skip_quote( name, '"', ',' ) ) {
address = g_strdup_printf( "\"%s\" <%s>", name, email->address );
}
else {
address = g_strdup_printf( "%s <%s>", name, email->address );
}
}
else {
address = g_strdup_printf( "%s", email->address );
}
return address;
}
2001-09-02 01:48:06 +02:00
/*
* End of Source.
*/