Re: Cleanup of libbalsa API 2




I just remembered - there is 3 new files which aren't in the patch.

They all go in libbalsa and are attached.

On Tue, 04 Jul 2000 19:38:17 Ian Campbell wrote:
> 
> Hi there,
> 
> I have put up a patch at
> http://www.btinternet.com/~ijc/balsa-renaming-2.patch.gz which does the same
> renaming as the last patch I sent, but also adds a load of other cleanups
and
> goes most of the way to making some stuff into GtkObjects. LibBalsaMessage
is
> done, and LibBalsaMailbox is mostly done.
> 
> [SNIP]
> -- 
> Ian Campbell 
> Churchill College,
> Cambridge.
> 
> _______________________________________________
> balsa-list mailing list
> balsa-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/balsa-list


-- 
Ian Campbell
Churchill College, Cambridge.
/* -*-mode:c; c-style:k&r; c-basic-offset:2; -*- */
/* Balsa E-Mail Client
 * Copyright (C) 1997-1999 Stuart Parmenter and Jay Painter
 *
 * 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, 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
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
 * 02111-1307, USA.
 */

#include "config.h"

#include <gnome.h>
#include <glib.h>

#include "libbalsa.h"

LibBalsaContact *
libbalsa_contact_new (void)
{
  LibBalsaContact *contact;

  contact = g_new (LibBalsaContact, 1);

  contact->card_name = NULL;
  contact->first_name = NULL;
  contact->last_name = NULL;
  contact->organization = NULL;
  contact->email_address = NULL;
  
  return contact;
}


void
libbalsa_contact_free (LibBalsaContact * contact)
{

  if (!contact)
    return;

  g_free(contact->card_name);
  g_free(contact->first_name);
  g_free(contact->last_name);  
  g_free(contact->organization);
  g_free(contact->email_address);
  
  g_free(contact);
}

void libbalsa_contact_list_free(GList * contact_list)
{
  GList *list;
  for (list = g_list_first (contact_list); list; list = g_list_next (list))
    if(list->data) libbalsa_contact_free (list->data);
  g_list_free (contact_list);
}

gint
libbalsa_contact_store(LibBalsaContact *contact, const gchar *fname)
{
    FILE *gc; 
    gchar string[256];
    gint in_vcard = FALSE;

    g_return_val_if_fail(fname, LIBBALSA_CONTACT_UNABLE_TO_OPEN_GNOMECARD_FILE);
    if(strlen(contact->card_name) == 0)
        return LIBBALSA_CONTACT_CARD_NAME_FIELD_EMPTY;

    gc = fopen(fname, "r+");
    
    if (!gc) 
        return LIBBALSA_CONTACT_UNABLE_TO_OPEN_GNOMECARD_FILE; 
            
    while (fgets(string, sizeof(string), gc)) 
    { 
        if ( g_strncasecmp(string, "BEGIN:VCARD", 11) == 0 ) {
            in_vcard = TRUE;
            continue;
        }
                
        if ( g_strncasecmp(string, "END:VCARD", 9) == 0 ) {
            in_vcard = FALSE;
            continue;
        }
        
        if (!in_vcard) continue;
        
        g_strchomp(string);
                
        if ( g_strncasecmp(string, "FN:", 3) == 0 )
        {
            gchar *id = g_strdup(string+3);
            if(g_strcasecmp(id, contact->card_name) == 0)
            {
                g_free(id);
                fclose(gc);
                return LIBBALSA_CONTACT_CARD_NAME_EXISTS;
            }
            g_free(id);
            continue;
        }
    }

    fprintf(gc, "\nBEGIN:VCARD\n");
    fprintf(gc, g_strdup_printf( "FN:%s\n", contact->card_name));

    if(strlen(contact->first_name) || strlen(contact->last_name))
        fprintf(gc, g_strdup_printf( "N:%s;%s\n", contact->last_name, contact->first_name));

    if(strlen(contact->organization))
        fprintf(gc, g_strdup_printf( "ORG:%s\n", contact->organization));
            
    if(strlen(contact->email_address))
        fprintf(gc, g_strdup_printf( "EMAIL;INTERNET:%s\n", contact->email_address));
            
    fprintf(gc, "END:VCARD\n");
    
    fclose(gc);
    return LIBBALSA_CONTACT_CARD_STORED_SUCCESSFULLY;
}
/* -*-mode:c; c-style:k&r; c-basic-offset:2; -*- */
/* Balsa E-Mail Client
 * Copyright (C) 1997-1999 Stuart Parmenter and Jay Painter
 *
 * 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, 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
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
 * 02111-1307, USA.
 */

#include "config.h"

#include <glib.h>

#include "libbalsa.h"

/*
 * body
 */
LibBalsaMessageBody *
libbalsa_message_body_new ()
{
  LibBalsaMessageBody *body;

  body = g_new (LibBalsaMessageBody, 1);
  body->htmlized = NULL;
  body->buffer = NULL;
  body->mutt_body = NULL;
  body->filename = NULL;
  body->charset  = NULL;
  return body;
}


void
libbalsa_message_body_free (LibBalsaMessageBody * body)
{
  if (!body)
    return;

  g_free (body->htmlized);
  g_free (body->buffer);
  g_free (body->filename);
  g_free (body->charset);
  g_free (body->buffer);
  g_free (body);
}

/* -*-mode:c; c-style:k&r; c-basic-offset:2; -*- */
/* Balsa E-Mail Client
 * Copyright (C) 1997-1999 Stuart Parmenter and Jay Painter
 *
 * 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, 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
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
 * 02111-1307, USA.
 */

#include "config.h"

#include <glib.h>

#include "libbalsa.h"
#include "libbalsa_private.h"

/*
 * addresses
 */
LibBalsaAddress *
libbalsa_address_new (void)
{
  LibBalsaAddress *address;

  address = g_new(LibBalsaAddress, 1);

  address->personal = NULL;
  address->mailbox = NULL;

  return address;
}

/* returns only first address on the list; ignores remaining ones */
LibBalsaAddress*
libbalsa_address_new_from_string(gchar* str) {
  ADDRESS *address = NULL;
  LibBalsaAddress *addr = NULL;

  address = rfc822_parse_adrlist (address, str);
  addr = libbalsa_address_new_from_libmutt (address);
  rfc822_free_address (&address);
  return addr;
}

GList *
libbalsa_address_new_list_from_string (gchar * the_str)
{
  ADDRESS *address = NULL;
  LibBalsaAddress *addr = NULL;
  GList *list = NULL;
  address = rfc822_parse_adrlist (address, the_str);

  while (address)
    {
      addr = libbalsa_address_new_from_libmutt (address);
      list = g_list_append (list, addr);
      address = address->next;
    }
  rfc822_free_address( &address );
  return list;
}

LibBalsaAddress *
libbalsa_address_new_from_libmutt (ADDRESS * caddr)
{
  LibBalsaAddress *address;

  if (!caddr)
    return NULL;
  address = libbalsa_address_new ();
  address->personal = g_strdup (caddr->personal);
  address->mailbox = g_strdup (caddr->mailbox);

  return address;
}

gchar *
libbalsa_address_to_gchar (LibBalsaAddress * addr)
{
  gchar *retc = NULL;

  if (addr->personal) {
     if(addr->mailbox)
	retc= g_strdup_printf("%s <%s>", addr->personal, addr->mailbox);
     else retc = g_strdup(addr->personal);
  } else
     if(addr->mailbox)
	retc = g_strdup(addr->mailbox);
  
  return retc;
}

void
libbalsa_address_free (LibBalsaAddress * address)
{

  if (!address)
    return;

  g_free (address->personal);
  g_free (address->mailbox);

  g_free (address);
}

void libbalsa_address_list_free(GList * address_list)
{
  GList *list;
  for (list = g_list_first (address_list); list; list = g_list_next (list))
    if(list->data) libbalsa_address_free (list->data);
  g_list_free (address_list);
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]