aboutsummaryrefslogtreecommitdiffstats
path: root/mail/folder-browser.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-11-22 06:09:51 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-11-22 06:09:51 +0800
commit0fa1b87e9ee6b947b2706a44fc7429730655b3f9 (patch)
tree186d98fc1423fdd9d86a85a251c78230a2c3060c /mail/folder-browser.c
parentfb92b831ae35b70f52a9792422f610defa56517b (diff)
downloadgsoc2013-evolution-0fa1b87e9ee6b947b2706a44fc7429730655b3f9.tar.gz
gsoc2013-evolution-0fa1b87e9ee6b947b2706a44fc7429730655b3f9.tar.zst
gsoc2013-evolution-0fa1b87e9ee6b947b2706a44fc7429730655b3f9.zip
New function to return if user wants to view message source.
2000-11-21 Jeffrey Stedfast <fejj@helixcode.com> * mail-config.c (mail_config_view_source): New function to return if user wants to view message source. (mail_config_set_view_source): New function to set whether the view wants to view source. * mail-ops.c (mail_do_view_message_sources): Removed. We're not gonna view-source this way anymore. * folder-browser-factory.c: Removed the ViewSource bonobo verb from the Message menu. (control_activate): Added ViewSource. * folder-browser.c (on_right_click): Removed Message menu item to view message source. (folder_browser_toggle_view_source): New callback to set whether or not the MailDisplay shows the raw message or the pretty-ified message. * mail-callbacks.c: Removed view_source. * mail-display.c (redisplay): If toggle_raw is set then display the raw message else display the pretty formatted message. (mail_display_redisplay): New function to force the redisplay of a message. * mail-format.c (mail_format_raw_message): New function to write the raw message data. svn path=/trunk/; revision=6639
Diffstat (limited to 'mail/folder-browser.c')
-rw-r--r--mail/folder-browser.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/mail/folder-browser.c b/mail/folder-browser.c
index f6c1b94963..d03e58eaa4 100644
--- a/mail/folder-browser.c
+++ b/mail/folder-browser.c
@@ -382,6 +382,22 @@ folder_browser_toggle_threads (BonoboUIComponent *component,
}
void
+folder_browser_toggle_view_source (BonoboUIComponent *component,
+ const char *path,
+ Bonobo_UIComponent_EventType type,
+ const char *state,
+ gpointer user_data)
+{
+ FolderBrowser *fb = user_data;
+
+ if (type != Bonobo_UIComponent_STATE_CHANGED)
+ return;
+
+ mail_config_set_view_source (atoi (state));
+ mail_display_redisplay (fb->mail_display, TRUE);
+}
+
+void
vfolder_subject (GtkWidget *w, FolderBrowser *fb)
{
vfolder_gui_add_from_message (fb->mail_display->current_message, AUTO_SUBJECT,
@@ -481,8 +497,6 @@ on_right_click (ETableScrolled *table, gint row, gint col, GdkEvent *event, Fold
{ _("Apply Filters"), NULL, GTK_SIGNAL_FUNC (apply_filters), NULL, 0 },
{ "", NULL, GTK_SIGNAL_FUNC (NULL), NULL, 0 },
{ _("Create Rule From Message"), NULL, GTK_SIGNAL_FUNC (NULL), filter_menu, 2 },
- { "", NULL, GTK_SIGNAL_FUNC (NULL), NULL, 0 },
- { _("View Message Source"), NULL, GTK_SIGNAL_FUNC (view_source), NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
@@ -721,7 +735,7 @@ my_folder_browser_init (GtkObject *object)
*/
fb->message_list = (MessageList *)message_list_new ();
fb->mail_display = (MailDisplay *)mail_display_new ();
-
+
gtk_signal_connect (GTK_OBJECT (fb->message_list->etable),
"key_press", GTK_SIGNAL_FUNC (etable_key), fb);
#n255'>255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
/*
 *  Copyright (C) 2000 Helix Code Inc.
 *
 *  Authors: Michael Zucchi <notzed@helixcode.com>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library 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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "camel-mime-utils.h"
#include "camel-internet-address.h"

#include <stdio.h>
#include <string.h>

#define d(x) 

static int    internet_decode       (CamelAddress *, const char *raw);
static char * internet_encode       (CamelAddress *);
static int    internet_unformat     (CamelAddress *, const char *raw);
static char * internet_format       (CamelAddress *);
static int    internet_cat      (CamelAddress *dest, const CamelAddress *source);
static void   internet_remove       (CamelAddress *, int index);

static void camel_internet_address_class_init (CamelInternetAddressClass *klass);
static void camel_internet_address_init       (CamelInternetAddress *obj);

static CamelAddressClass *camel_internet_address_parent;

struct _address {
    char *name;
    char *address;
};

static void
camel_internet_address_class_init(CamelInternetAddressClass *klass)
{
    CamelAddressClass *address = (CamelAddressClass *) klass;

    camel_internet_address_parent = CAMEL_ADDRESS_CLASS(camel_type_get_global_classfuncs(camel_address_get_type()));

    address->decode = internet_decode;
    address->encode = internet_encode;
    address->unformat = internet_unformat;
    address->format = internet_format;
    address->remove = internet_remove;
    address->cat = internet_cat;
}

static void
camel_internet_address_init(CamelInternetAddress *obj)
{
}

CamelType
camel_internet_address_get_type(void)
{
    static CamelType type = CAMEL_INVALID_TYPE;
    
    if (type == CAMEL_INVALID_TYPE) {
        type = camel_type_register(camel_address_get_type(), "CamelInternetAddress",
                       sizeof (CamelInternetAddress),
                       sizeof (CamelInternetAddressClass),
                       (CamelObjectClassInitFunc) camel_internet_address_class_init,
                       NULL,
                       (CamelObjectInitFunc) camel_internet_address_init,
                       NULL);
    }
    
    return type;
}

static int
internet_decode (CamelAddress *a, const char *raw)
{
    struct _header_address *ha, *n;
    int count = a->addresses->len;

    /* Should probably use its own decoder or something */
    ha = header_address_decode(raw);
    if (ha) {
        n = ha;
        while (n) {
            if (n->type == HEADER_ADDRESS_NAME) {
                camel_internet_address_add((CamelInternetAddress *)a, n->name, n->v.addr);
            } else if (n->type == HEADER_ADDRESS_GROUP) {
                struct _header_address *g = n->v.members;
                while (g) {
                    if (g->type == HEADER_ADDRESS_NAME)
                        camel_internet_address_add((CamelInternetAddress *)a, g->name, g->v.addr);
                    /* otherwise, it's an error, infact */
                    g = g->next;
                }
            }
            n = n->next;
        }
        header_address_list_clear(&ha);
    }
    
    return a->addresses->len - count;
}

static char *
internet_encode (CamelAddress *a)
{
    int i;
    GString *out;
    char *ret;
    int len = 6;        /* "From: ", assume longer of the address headers */

    if (a->addresses->len == 0)
        return NULL;
    
    out = g_string_new("");
    
    for (i = 0;i < a->addresses->len; i++) {
        struct _address *addr = g_ptr_array_index(a->addresses, i);
        char *enc;

        if (i != 0)
            g_string_append(out, ", ");

        enc = camel_internet_address_encode_address(&len, addr->name, addr->address);
        g_string_sprintfa(out, "%s", enc);
        g_free(enc);
    }
    
    ret = out->str;
    g_string_free(out, FALSE);
    
    return ret;
}

static int
internet_unformat(CamelAddress *a, const char *raw)
{
    char *buffer, *p, *name, *addr;
    int c;
    int count = a->addresses->len;

    if (raw == NULL)
        return 0;

    d(printf("unformatting address: %s\n", raw));

    /* we copy, so we can modify as we go */
    buffer = g_strdup(raw);

    /* this can be simpler than decode, since there are much fewer rules */
    p = buffer;
    name = NULL;
    addr = p;
    do {
        c = (unsigned char)*p++;
        switch (c) {
            /* removes quotes, they should only be around the total name anyway */
        case '"':
            p[-1] = ' ';
            while (*p)
                if (*p == '"') {
                    *p++ = ' ';
                    break;
                } else {
                    p++;
                }
            break;
        case '<':
            if (name == NULL)
                name = addr;
            addr = p;
            addr[-1] = 0;
            while (*p && *p != '>')
                p++;
            if (*p == 0)
                break;
            p++;
            /* falls through */
        case ',':
            p[-1] = 0;
            /* falls through */
        case 0:
            if (name)
                name = g_strstrip(name);
            addr = g_strstrip(addr);
            if (addr[0]) {
                d(printf("found address: '%s' <%s>\n", name, addr));
                camel_internet_address_add((CamelInternetAddress *)a, name, addr);
            }
            name = NULL;
            addr = p;
            break;
        }
    } while (c);

    g_free(buffer);

    return a->addresses->len - count;
}

static char *
internet_format (CamelAddress *a)
{
    int i;
    GString *out;
    char *ret;
    
    if (a->addresses->len == 0)
        return NULL;
    
    out = g_string_new("");
    
    for (i = 0;i < a->addresses->len; i++) {
        struct _address *addr = g_ptr_array_index(a->addresses, i);
        char *enc;

        if (i != 0)
            g_string_append(out, ", ");

        enc = camel_internet_address_format_address(addr->name, addr->address);
        g_string_sprintfa(out, "%s", enc);
        g_free(enc);
    }
    
    ret = out->str;
    g_string_free(out, FALSE);
    
    return ret;
}

static int    internet_cat      (CamelAddress *dest, const CamelAddress *source)
{
    int i;

    g_assert(CAMEL_IS_INTERNET_ADDRESS(source));

    for (i=0;i<source->addresses->len;i++) {
        struct _address *addr = g_ptr_array_index(source->addresses, i);
        camel_internet_address_add((CamelInternetAddress *)dest, addr->name, addr->address);
    }

    return i;
}

static void
internet_remove (CamelAddress *a, int index)
{
    struct _address *addr;
    
    if (index < 0 || index >= a->addresses->len)
        return;
    
    addr = g_ptr_array_index(a->addresses, index);
    g_free(addr->name);
    g_free(addr->address);
    g_free(addr);
    g_ptr_array_remove_index(a->addresses, index);
}

/**
 * camel_internet_address_new:
 *
 * Create a new CamelInternetAddress object.
 * 
 * Return value: A new CamelInternetAddress object.
 **/
CamelInternetAddress *
camel_internet_address_new (void)
{
    CamelInternetAddress *new = CAMEL_INTERNET_ADDRESS(camel_object_new(camel_internet_address_get_type()));
    return new;
}

/**
 * camel_internet_address_add:
 * @a: internet address object
 * @name: 
 * @address: 
 * 
 * Add a new internet address to the address object.
 * 
 * Return value: Index of added entry.
 **/
int
camel_internet_address_add  (CamelInternetAddress *a, const char *name, const char *address)
{
    struct _address *new;
    int index;

    g_assert(CAMEL_IS_INTERNET_ADDRESS(a));

    new = g_malloc(sizeof(*new));
    new->name = g_strdup(name);
    new->address = g_strdup(address);
    index = ((CamelAddress *)a)->addresses->len;
    g_ptr_array_add(((CamelAddress *)a)->addresses, new);

    return index;
}

/**
 * camel_internet_address_get:
 * @a: internet address object
 * @index: address's array index
 * @namep: Holder for the returned name, or NULL, if not required.
 * @addressp: Holder for the returned address, or NULL, if not required.
 * 
 * Get the address at @index.
 * 
 * Return value: TRUE if such an address exists, or FALSE otherwise.
 **/
gboolean
camel_internet_address_get  (const CamelInternetAddress *a, int index, const char **namep, const char **addressp)
{
    struct _address *addr;

    g_assert(CAMEL_IS_INTERNET_ADDRESS(a));

    if (index < 0 || index >= ((CamelAddress *)a)->addresses->len)
        return FALSE;

    addr = g_ptr_array_index( ((CamelAddress *)a)->addresses, index);
    if (namep)
        *namep = addr->name;
    if (addressp)
        *addressp = addr->address;
    return TRUE;
}

/**
 * camel_internet_address_find_name:
 * @a: 
 * @name: 
 * @addressp: Holder for address part, or NULL, if not required.
 * 
 * Find address by real name.
 * 
 * Return value: The index of the address matching the name, or -1
 * if no match was found.
 **/
int
camel_internet_address_find_name(CamelInternetAddress *a, const char *name, const char **addressp)
{
    struct _address *addr;
    int i, len;

    g_assert(CAMEL_IS_INTERNET_ADDRESS(a));

    len = ((CamelAddress *)a)->addresses->len;
    for (i=0;i<len;i++) {
        addr = g_ptr_array_index( ((CamelAddress *)a)->addresses, i );
        if (!strcmp(addr->name, name)) {
            if (addressp)
                *addressp = addr->address;
            return i;
        }
    }
    return -1;
}

/**
 * camel_internet_address_find_address:
 * @a: 
 * @address: 
 * @namep: Return for the matching name, or NULL, if not required.
 * 
 * Find an address by address.
 * 
 * Return value: The index of the address, or -1 if not found.
 **/
int
camel_internet_address_find_address(CamelInternetAddress *a, const char *address, const char **namep)
{
    struct _address *addr;
    int i, len;

    g_assert(CAMEL_IS_INTERNET_ADDRESS(a));

    len = ((CamelAddress *)a)->addresses->len;
    for (i=0;i<len;i++) {
        addr = g_ptr_array_index( ((CamelAddress *)a)->addresses, i );
        if (!strcmp(addr->address, address)) {
            if (namep)
                *namep = addr->name;
            return i;
        }
    }
    return -1;
}

/**
 * camel_internet_address_encode_address:
 * @len: The encoded length so far, of this line
 * @name: 
 * @addr: 
 * 
 * Encode a single address ready for internet usage.  Header folding
 * as per rfc 822 is also performed, based on the length in len.
 * 
 * Return value: The encoded address.
 **/
char *
camel_internet_address_encode_address(int *inlen, const char *real, const char *addr)
{
    char *name = header_encode_phrase(real);
    char *ret = NULL, *addra = NULL;
    int len = *inlen;
    GString *out = g_string_new("");

    g_assert(addr);

    if (name && name[0]) {
        if (strlen(name) + len > CAMEL_FOLD_SIZE) {
            char *folded = header_fold(name, len);
            char *last;
            g_string_append(out, folded);
            g_free(folded);
            last = strrchr(out->str, '\n');
            if (last)
                len = last-(out->str+out->len);
            else
                len = out->len;
        } else {
            g_string_append(out, name);
            len += strlen(name);
        }
        addr = addra = g_strdup_printf(" <%s>", addr);
    }

    /* NOTE: Strictly speaking, we could and should split the
     * internal address up if we need to, on atom or specials
     * boundaries - however, to aid interoperability with mailers
     * that will probably not handle this case, we will just move
     * the whole address to its own line */
    if (strlen(addr) + len > CAMEL_FOLD_SIZE) {
        g_string_append(out, "\n\t");
        g_string_append(out, addr);
        len = strlen(addr)+1;
    } else {
        g_string_append(out, addr);
        len += strlen(addr);
    }

    *inlen = len;
#if 0
    if (name && name[0])
        ret = g_strdup_printf("%s <%s>", name, addr);
    else
        ret = g_strdup_printf("%s", addr);
#endif
    g_free(name);
    g_free(addra);
    
    ret = out->str;
    g_string_free(out, FALSE);

    return ret;
}

/**
 * camel_internet_address_format_address:
 * @name: A name, quotes may be stripped from it.
 * @addr: Assumes a valid rfc822 email address.
 * 
 * Function to format a single address, suitable for display.
 * 
 * Return value: 
 **/
char *
camel_internet_address_format_address(const char *name, const char *addr)
{
    char *ret = NULL;

    g_assert(addr);

    if (name && name[0]) {
        const char *p = name;
        char *o, c;

        while ((c = *p++)) {
            if (c == '\"' || c == ',') {
                o = ret = g_malloc(strlen(name)+3+strlen(addr)+3 + 1);
                p = name;
                *o++ = '\"';
                while ((c = *p++))
                    if (c != '\"')
                        *o++ = c;
                *o++ = '\"';
                sprintf(o, " <%s>", addr);
                d(printf("encoded '%s' => '%s'\n", name, ret));
                return ret;
            }
        }
        ret = g_strdup_printf("%s <%s>", name, addr);
    } else
        ret = g_strdup(addr);

    return ret;
}