aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-06-16 05:12:14 +0800
committerGitHub <noreply@github.com>2017-06-16 05:12:14 +0800
commit41a1ce037b975e5d69a8bd1f977ec92794621f9b (patch)
treefb8989c31ab9e607cadb6a1b0ecd6465562e321c /app
parent08b8e89b88678b9fbe2816b0501d700deba8bb97 (diff)
parent27b874f2c48fd1cb9dc0984646cb739173ddaf2c (diff)
downloadtangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.tar.gz
tangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.tar.zst
tangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.zip
Merge pull request #1611 from MetaMask/checkTxsOnSync
add a check for weather a tx is included in a block when jumping blocks
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/transactions.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 71f90c2cd..9c20a7f1a 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -26,6 +26,8 @@ module.exports = class TransactionController extends EventEmitter {
this.txProviderUtils = new TxProviderUtil(this.query)
this.blockTracker.on('block', this.checkForTxInBlock.bind(this))
this.blockTracker.on('block', this.resubmitPendingTxs.bind(this))
+ // provider-engine only exploses the 'block' event, not 'latest' for 'sync'
+ this.provider._blockTracker.on('sync', this.queryPendingTxs.bind(this))
this.signEthTx = opts.signTransaction
this.nonceLock = Semaphore(1)
@@ -359,6 +361,17 @@ module.exports = class TransactionController extends EventEmitter {
})
}
+ queryPendingTxs ({oldBlock, newBlock}) {
+ // check pending transactions on start
+ if (!oldBlock) {
+ this._checkPendingTxs()
+ return
+ }
+ // if we synced by more than one block, check for missed pending transactions
+ const diff = Number.parseInt(newBlock.number) - Number.parseInt(oldBlock.number)
+ if (diff > 1) this._checkPendingTxs()
+ }
+
// PRIVATE METHODS
// Should find the tx in the tx list and
@@ -433,6 +446,39 @@ module.exports = class TransactionController extends EventEmitter {
this.txProviderUtils.publishTransaction(rawTx, cb)
}
+ // checks the network for signed txs and
+ // if confirmed sets the tx status as 'confirmed'
+ _checkPendingTxs () {
+ var signedTxList = this.getFilteredTxList({status: 'submitted'})
+ if (!signedTxList.length) return
+ signedTxList.forEach((txMeta) => {
+ var txHash = txMeta.hash
+ var txId = txMeta.id
+ if (!txHash) {
+ const errReason = {
+ errCode: 'No hash was provided',
+ message: 'We had an error while submitting this transaction, please try again.',
+ }
+ return this.setTxStatusFailed(txId, errReason)
+ }
+ this.query.getTransactionByHash(txHash, (err, txParams) => {
+ if (err || !txParams) {
+ if (!txParams) return
+ txMeta.err = {
+ isWarning: true,
+ errorCode: err,
+ message: 'There was a problem loading this transaction.',
+ }
+ this.updateTx(txMeta)
+ return log.error(err)
+ }
+ if (txParams.blockNumber) {
+ this.setTxStatusConfirmed(txId)
+ }
+ })
+ })
+ }
+
}
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 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
/*
 * e-mail-config-identity-page.c
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 */

#include "e-mail-config-identity-page.h"

#include <config.h>
#include <glib/gi18n-lib.h>

#include <libebackend/libebackend.h>

#include <e-util/e-marshal.h>
#include <misc/e-mail-signature-combo-box.h>
#include <misc/e-mail-signature-editor.h>

#define E_MAIL_CONFIG_IDENTITY_PAGE_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_MAIL_CONFIG_IDENTITY_PAGE, EMailConfigIdentityPagePrivate))

struct _EMailConfigIdentityPagePrivate {
    ESource *identity_source;
    ESourceRegistry *registry;
    gboolean show_account_info;
    gboolean show_instructions;
    gboolean show_signatures;
};

enum {
    PROP_0,
    PROP_IDENTITY_SOURCE,
    PROP_REGISTRY,
    PROP_SHOW_ACCOUNT_INFO,
    PROP_SHOW_INSTRUCTIONS,
    PROP_SHOW_SIGNATURES
};

/* Forward Declarations */
static void e_mail_config_identity_page_interface_init
                    (EMailConfigPageInterface *interface);

G_DEFINE_TYPE_WITH_CODE (
    EMailConfigIdentityPage,
    e_mail_config_identity_page,
    GTK_TYPE_BOX,
    G_IMPLEMENT_INTERFACE (
        E_TYPE_EXTENSIBLE, NULL)
    G_IMPLEMENT_INTERFACE (
        E_TYPE_MAIL_CONFIG_PAGE,
        e_mail_config_identity_page_interface_init))

static gboolean
mail_config_identity_page_is_email (const gchar *email_address)
{
    const gchar *cp;

    /* Make sure we have a '@' between a name and domain part. */
    cp = strchr (email_address, '@');

    return (cp != NULL && cp != email_address && *(cp + 1) != '\0');
}

static void
mail_config_identity_page_add_signature_cb (GtkButton *button,
                                            EMailConfigIdentityPage *page)
{
    ESourceRegistry *registry;
    GtkWidget *editor;

    registry = e_mail_config_identity_page_get_registry (page);

    editor = e_mail_signature_editor_new (registry, NULL);
    gtk_window_set_position (GTK_WINDOW (editor), GTK_WIN_POS_CENTER);
    gtk_widget_show (editor);
}

static void
mail_config_identity_page_set_registry (EMailConfigIdentityPage *page,
                                        ESourceRegistry *registry)
{
    g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
    g_return_if_fail (page->priv->registry == NULL);

    page->priv->registry = g_object_ref (registry);
}

static void
mail_config_identity_page_set_identity_source (EMailConfigIdentityPage *page,
                                               ESource *identity_source)
{
    g_return_if_fail (E_IS_SOURCE (identity_source));
    g_return_if_fail (page->priv->identity_source == NULL);

    page->priv->identity_source = g_object_ref (identity_source);
}

static void
mail_config_identity_page_set_property (GObject *object,
                                        guint property_id,
                                        const GValue *value,
                                        GParamSpec *pspec)
{
    switch (property_id) {
        case PROP_IDENTITY_SOURCE:
            mail_config_identity_page_set_identity_source (
                E_MAIL_CONFIG_IDENTITY_PAGE (object),
                g_value_get_object (value));
            return;

        case PROP_REGISTRY:
            mail_config_identity_page_set_registry (
                E_MAIL_CONFIG_IDENTITY_PAGE (object),
                g_value_get_object (value));
            return;

        case PROP_SHOW_ACCOUNT_INFO:
            e_mail_config_identity_page_set_show_account_info (
                E_MAIL_CONFIG_IDENTITY_PAGE (object),
                g_value_get_boolean (value));
            return;

        case PROP_SHOW_INSTRUCTIONS:
            e_mail_config_identity_page_set_show_instructions (
                E_MAIL_CONFIG_IDENTITY_PAGE (object),
                g_value_get_boolean (value));
            return;

        case PROP_SHOW_SIGNATURES:
            e_mail_config_identity_page_set_show_signatures (
                E_MAIL_CONFIG_IDENTITY_PAGE (object),
                g_value_get_boolean (value));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
mail_config_identity_page_get_property (GObject *object,
                                        guint property_id,
                                        GValue *value,
                                        GParamSpec *pspec)
{
    switch (property_id) {
        case PROP_IDENTITY_SOURCE:
            g_value_set_object (
                value,
                e_mail_config_identity_page_get_identity_source (
                E_MAIL_CONFIG_IDENTITY_PAGE (object)));
            return;

        case PROP_REGISTRY:
            g_value_set_object (
                value,
                e_mail_config_identity_page_get_registry (
                E_MAIL_CONFIG_IDENTITY_PAGE (object)));
            return;

        case PROP_SHOW_ACCOUNT_INFO:
            g_value_set_boolean (
                value,
                e_mail_config_identity_page_get_show_account_info (
                E_MAIL_CONFIG_IDENTITY_PAGE (object)));
            return;

        case PROP_SHOW_INSTRUCTIONS:
            g_value_set_boolean (
                value,
                e_mail_config_identity_page_get_show_instructions (
                E_MAIL_CONFIG_IDENTITY_PAGE (object)));
            return;

        case PROP_SHOW_SIGNATURES:
            g_value_set_boolean (
                value,
                e_mail_config_identity_page_get_show_signatures (
                E_MAIL_CONFIG_IDENTITY_PAGE (object)));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
mail_config_identity_page_dispose (GObject *object)
{
    EMailConfigIdentityPagePrivate *priv;

    priv = E_MAIL_CONFIG_IDENTITY_PAGE_GET_PRIVATE (object);

    if (priv->identity_source != NULL) {
        g_object_unref (priv->identity_source);
        priv->identity_source = NULL;
    }

    if (priv->registry != NULL) {
        g_object_unref (priv->registry);
        priv->registry = NULL;
    }

    /* Chain up to parent's dispose() method. */
    G_OBJECT_CLASS (e_mail_config_identity_page_parent_class)->
        dispose (object);
}

static void
mail_config_identity_page_constructed (GObject *object)
{
    EMailConfigIdentityPage *page;
    ESource *source;
    ESourceRegistry *registry;
    ESourceMailIdentity *extension;
    GtkLabel *label;
    GtkWidget *widget;
    GtkWidget *container;
    GtkSizeGroup *size_group;
    const gchar *extension_name;
    const gchar *text;
    gchar *markup;

    page = E_MAIL_CONFIG_IDENTITY_PAGE (object);

    /* Chain up to parent's constructed() method. */
    G_OBJECT_CLASS (e_mail_config_identity_page_parent_class)->
        constructed (object);

    extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
    registry = e_mail_config_identity_page_get_registry (page);
    source = e_mail_config_identity_page_get_identity_source (page);
    extension = e_source_get_extension (source, extension_name);

    gtk_orientable_set_orientation (
        GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL);

    gtk_box_set_spacing (GTK_BOX (page), 12);

    /* This keeps all mnemonic labels the same width. */
    size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
    gtk_size_group_set_ignore_hidden (size_group, TRUE);

    text = _("Please enter your name and email address below. "
         "The \"optional\" fields below do not need to be filled "
         "in, unless you wish to include this information in email "
         "you send.");
    widget = gtk_label_new (text);
    gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
    gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);

    g_object_bind_property (
        page, "show-instructions",
        widget, "visible",
        G_BINDING_SYNC_CREATE);

    /*** Account Information ***/

    widget = gtk_grid_new ();
    gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
    gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
    gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);

    g_object_bind_property (
        page, "show-account-info",
        widget, "visible",
        G_BINDING_SYNC_CREATE);

    container = widget;

    text = _("Account Information");
    markup = g_markup_printf_escaped ("<b>%s</b>", text);
    widget = gtk_label_new (markup);
    gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
    gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 2, 1);
    gtk_widget_show (widget);
    g_free (markup);

    text = _("Type the name by which you would like to refer to "
         "this account.\nFor example, \"Work\" or \"Personal\".");
    widget = gtk_label_new (text);
    gtk_widget_set_margin_left (widget, 12);
    gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 2, 1);
    gtk_widget_show (widget);

    text = _("_Name:");
    widget = gtk_label_new_with_mnemonic (text);
    gtk_widget_set_margin_left (widget, 12);
    gtk_size_group_add_widget (size_group, widget);
    gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
    gtk_widget_show (widget);

    label = GTK_LABEL (widget);

    widget = gtk_entry_new ();
    gtk_widget_set_hexpand (widget, TRUE);
    gtk_label_set_mnemonic_widget (label, widget);
    gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 1, 1);
    gtk_widget_show (widget);

    g_object_bind_property (
        source, "display-name",
        widget, "text",
        G_BINDING_BIDIRECTIONAL |
        G_BINDING_SYNC_CREATE);

    /* This entry affects the "check-complete" result. */
    g_signal_connect_swapped (
        widget, "changed",
        G_CALLBACK (e_mail_config_page_changed), page);

    /*** Required Information ***/

    widget = gtk_grid_new ();
    gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
    gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
    gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
    gtk_widget_show (widget);

    container = widget;

    text = _("Required Information");
    markup = g_markup_printf_escaped ("<b>%s</b>", text);
    widget = gtk_label_new (markup);
    gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
    gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 2, 1);
    gtk_widget_show (widget);
    g_free (markup);

    text = _("Full Nam_e:");
    widget = gtk_label_new_with_mnemonic (text);
    gtk_widget_set_margin_left (widget, 12);
    gtk_size_group_add_widget (size_group, widget);
    gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
    gtk_widget_show (widget);

    label = GTK_LABEL (widget);

    widget = gtk_entry_new ();
    gtk_widget_set_hexpand (widget, TRUE);
    gtk_label_set_mnemonic_widget (label, widget);
    gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 1, 1);
    gtk_widget_show (widget);

    g_object_bind_property (
        extension, "name",
        widget, "text",
        G_BINDING_BIDIRECTIONAL |
        G_BINDING_SYNC_CREATE);

    /* This entry affects the "check-complete" result. */
    g_signal_connect_swapped (
        widget, "changed",
        G_CALLBACK (e_mail_config_page_changed), page);

    text = _("Email _Address:");
    widget = gtk_label_new_with_mnemonic (text);
    gtk_widget_set_margin_left (widget, 12);
    gtk_size_group_add_widget (size_group, widget);
    gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
    gtk_widget_show (widget);

    label = GTK_LABEL (widget);

    widget = gtk_entry_new ();
    gtk_widget_set_hexpand (widget, TRUE);
    gtk_label_set_mnemonic_widget (label, widget);
    gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 1, 1);
    gtk_widget_show (widget);

    g_object_bind_property (
        extension, "address",
        widget, "text",
        G_BINDING_BIDIRECTIONAL |
        G_BINDING_SYNC_CREATE);

    /* This entry affects the "check-complete" result. */
    g_signal_connect_swapped (
        widget, "changed",
        G_CALLBACK (e_mail_config_page_changed), page);

    /*** Optional Information ***/

    widget = gtk_grid_new ();
    gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
    gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
    gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
    gtk_widget_show (widget);

    container = widget;

    text = _("Optional Information");
    markup = g_markup_printf_escaped ("<b>%s</b>", text);
    widget = gtk_label_new (markup);
    gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
    gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 3, 1);
    gtk_widget_show (widget);

    text = _("Re_ply-To:");
    widget = gtk_label_new_with_mnemonic (text);
    gtk_widget_set_margin_left (widget, 12);
    gtk_size_group_add_widget (size_group, widget);
    gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
    gtk_widget_show (widget);

    label = GTK_LABEL (widget);

    widget = gtk_entry_new ();
    gtk_widget_set_hexpand (widget, TRUE);
    gtk_label_set_mnemonic_widget (label, widget);
    gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 2, 1);
    gtk_widget_show (widget);

    g_object_bind_property (
        extension, "reply-to",
        widget, "text",
        G_BINDING_BIDIRECTIONAL |
        G_BINDING_SYNC_CREATE);

    /* This entry affects the "check-complete" result. */
    g_signal_connect_swapped (
        widget, "changed",
        G_CALLBACK (e_mail_config_page_changed), page);

    text = _("Or_ganization:");
    widget = gtk_label_new_with_mnemonic (text);
    gtk_widget_set_margin_left (widget, 12);
    gtk_size_group_add_widget (size_group, widget);
    gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
    gtk_widget_show (widget);

    label = GTK_LABEL (widget);

    widget = gtk_entry_new ();
    gtk_widget_set_hexpand (widget, TRUE);
    gtk_label_set_mnemonic_widget (label, widget);
    gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 2, 1);
    gtk_widget_show (widget);

    g_object_bind_property (
        extension, "organization",
        widget, "text",
        G_BINDING_BIDIRECTIONAL |
        G_BINDING_SYNC_CREATE);

    text = _("Si_gnature:");
    widget = gtk_label_new_with_mnemonic (text);
    gtk_widget_set_margin_left (widget, 12);
    gtk_size_group_add_widget (size_group, widget);
    gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
    gtk_grid_attach (GTK_GRID (container), widget, 0, 3, 1, 1);
    gtk_widget_show (widget);

    g_object_bind_property (
        page, "show-signatures",
        widget, "visible",
        G_BINDING_SYNC_CREATE);

    label = GTK_LABEL (widget);

    widget = e_mail_signature_combo_box_new (registry);
    gtk_widget_set_hexpand (widget, TRUE);
    gtk_widget_set_halign (widget, GTK_ALIGN_START);
    gtk_label_set_mnemonic_widget (label, widget);
    gtk_grid_attach (GTK_GRID (container), widget, 1, 3, 1, 1);
    gtk_widget_show (widget);

    g_object_bind_property (
        extension, "signature-uid",
        widget, "active-id",
        G_BINDING_BIDIRECTIONAL |
        G_BINDING_SYNC_CREATE);

    g_object_bind_property (
        page, "show-signatures",
        widget, "visible",
        G_BINDING_SYNC_CREATE);

    text = _("Add Ne_w Signature...");
    widget = gtk_button_new_with_mnemonic (text);
    gtk_grid_attach (GTK_GRID (container), widget, 2, 3, 1, 1);
    gtk_widget_show (widget);

    g_object_bind_property (
        page, "show-signatures",
        widget, "visible",
        G_BINDING_SYNC_CREATE);

    g_signal_connect (
        widget, "clicked",
        G_CALLBACK (mail_config_identity_page_add_signature_cb), page);

    g_object_unref (size_group);

    e_extensible_load_extensions (E_EXTENSIBLE (page));
}

static gboolean
mail_config_identity_page_check_complete (EMailConfigPage *page)
{
    EMailConfigIdentityPage *id_page;
    ESource *source;
    ESourceMailIdentity *extension;
    const gchar *extension_name;
    const gchar *name;
    const gchar *address;
    const gchar *reply_to;
    const gchar *display_name;

    id_page = E_MAIL_CONFIG_IDENTITY_PAGE (page);
    extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
    source = e_mail_config_identity_page_get_identity_source (id_page);
    extension = e_source_get_extension (source, extension_name);

    name = e_source_mail_identity_get_name (extension);
    address = e_source_mail_identity_get_address (extension);
    reply_to = e_source_mail_identity_get_reply_to (extension);

    display_name = e_source_get_display_name (source);

    if (name == NULL)
        return FALSE;

    if (address == NULL)
        return FALSE;

    if (!mail_config_identity_page_is_email (address))
        return FALSE;

    /* A NULL reply_to string is allowed. */
    if (reply_to != NULL && !mail_config_identity_page_is_email (reply_to))
        return FALSE;

    /* Only enforce when account information is visible. */
    if (e_mail_config_identity_page_get_show_account_info (id_page))
        if (display_name == NULL || *display_name == '\0')
            return FALSE;

    return TRUE;
}

static void
e_mail_config_identity_page_class_init (EMailConfigIdentityPageClass *class)
{
    GObjectClass *object_class;

    g_type_class_add_private (
        class, sizeof (EMailConfigIdentityPagePrivate));

    object_class = G_OBJECT_CLASS (class);
    object_class->set_property = mail_config_identity_page_set_property;
    object_class->get_property = mail_config_identity_page_get_property;
    object_class->dispose = mail_config_identity_page_dispose;
    object_class->constructed = mail_config_identity_page_constructed;

    g_object_class_install_property (
        object_class,
        PROP_REGISTRY,
        g_param_spec_object (
            "registry",
            "Registry",
            "Registry of data sources",
            E_TYPE_SOURCE_REGISTRY,
            G_PARAM_READWRITE |
            G_PARAM_CONSTRUCT_ONLY |
            G_PARAM_STATIC_STRINGS));

    g_object_class_install_property (
        object_class,
        PROP_IDENTITY_SOURCE,
        g_param_spec_object (
            "identity-source",
            "Identity Source",
            "Mail identity source being edited",
            E_TYPE_SOURCE,
            G_PARAM_READWRITE |
            G_PARAM_CONSTRUCT_ONLY |
            G_PARAM_STATIC_STRINGS));

    g_object_class_install_property (
        object_class,
        PROP_SHOW_ACCOUNT_INFO,
        g_param_spec_boolean (
            "show-account-info",
            "Show Account Info",
            "Show the \"Account Information\" section",
            TRUE,
            G_PARAM_READWRITE |
            G_PARAM_CONSTRUCT |
            G_PARAM_STATIC_STRINGS));

    g_object_class_install_property (
        object_class,
        PROP_SHOW_INSTRUCTIONS,
        g_param_spec_boolean (
            "show-instructions",
            "Show Instructions",
            "Show helpful instructions",
            TRUE,
            G_PARAM_READWRITE |
            G_PARAM_CONSTRUCT |
            G_PARAM_STATIC_STRINGS));

    g_object_class_install_property (
        object_class,
        PROP_SHOW_SIGNATURES,
        g_param_spec_boolean (
            "show-signatures",
            "Show Signatures",
            "Show mail signature options",
            TRUE,
            G_PARAM_READWRITE |
            G_PARAM_CONSTRUCT |
            G_PARAM_STATIC_STRINGS));
}

static void
e_mail_config_identity_page_interface_init (EMailConfigPageInterface *interface)
{
    interface->title = _("Identity");
    interface->sort_order = E_MAIL_CONFIG_IDENTITY_PAGE_SORT_ORDER;
    interface->check_complete = mail_config_identity_page_check_complete;
}

static void
e_mail_config_identity_page_init (EMailConfigIdentityPage *page)
{
    page->priv = E_MAIL_CONFIG_IDENTITY_PAGE_GET_PRIVATE (page);
}

EMailConfigPage *
e_mail_config_identity_page_new (ESourceRegistry *registry,
                                 ESource *identity_source)
{
    g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
    g_return_val_if_fail (E_IS_SOURCE (identity_source), NULL);

    return g_object_new (
        E_TYPE_MAIL_CONFIG_IDENTITY_PAGE,
        "registry", registry,
        "identity-source", identity_source,
        NULL);
}

ESourceRegistry *
e_mail_config_identity_page_get_registry (EMailConfigIdentityPage *page)
{
    g_return_val_if_fail (E_IS_MAIL_CONFIG_IDENTITY_PAGE (page), NULL);

    return page->priv->registry;
}

ESource *
e_mail_config_identity_page_get_identity_source (EMailConfigIdentityPage *page)
{
    g_return_val_if_fail (E_IS_MAIL_CONFIG_IDENTITY_PAGE (page), NULL);

    return page->priv->identity_source;
}

gboolean
e_mail_config_identity_page_get_show_account_info (EMailConfigIdentityPage *page)
{
    g_return_val_if_fail (E_IS_MAIL_CONFIG_IDENTITY_PAGE (page), FALSE);

    return page->priv->show_account_info;
}

void
e_mail_config_identity_page_set_show_account_info (EMailConfigIdentityPage *page,
                                                   gboolean show_account_info)
{
    g_return_if_fail (E_IS_MAIL_CONFIG_IDENTITY_PAGE (page));

    if ((page->priv->show_account_info ? 1 : 0) == (show_account_info ? 1 : 0))
        return;

    page->priv->show_account_info = show_account_info;

    g_object_notify (G_OBJECT (page), "show-account-info");
}

gboolean
e_mail_config_identity_page_get_show_instructions (EMailConfigIdentityPage *page)
{
    g_return_val_if_fail (E_IS_MAIL_CONFIG_IDENTITY_PAGE (page), FALSE);

    return page->priv->show_instructions;
}

void
e_mail_config_identity_page_set_show_instructions (EMailConfigIdentityPage *page,
                                                   gboolean show_instructions)
{
    g_return_if_fail (E_IS_MAIL_CONFIG_IDENTITY_PAGE (page));

    if ((page->priv->show_instructions ? 1 : 0) == (show_instructions ? 1 : 0))
        return;

    page->priv->show_instructions = show_instructions;

    g_object_notify (G_OBJECT (page), "show-instructions");
}

gboolean
e_mail_config_identity_page_get_show_signatures (EMailConfigIdentityPage *page)
{
    g_return_val_if_fail (E_IS_MAIL_CONFIG_IDENTITY_PAGE (page), FALSE);

    return page->priv->show_signatures;
}

void
e_mail_config_identity_page_set_show_signatures (EMailConfigIdentityPage *page,
                                                 gboolean show_signatures)
{
    g_return_if_fail (E_IS_MAIL_CONFIG_IDENTITY_PAGE (page));

    if ((page->priv->show_signatures ? 1 : 0) == (show_signatures ? 1 : 0))
        return;

    page->priv->show_signatures = show_signatures;

    g_object_notify (G_OBJECT (page), "show-signatures");
}