emailnormalizer

package module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 1 Imported by: 2

README

go-email-normalizer - email normalization for Go

Build Status codecov Go Report Card License Mentioned in Awesome Go

This is Golang library for providing a canonical representation of email address. It allows to prevent multiple signups. go-email-normalizer contains some popular providers but you can easily append others.

Download

go get github.com/dimuska139/go-email-normalizer

Usage

package main

import (
	"fmt"
	"strings"
	normalizer "github.com/dimuska139/go-email-normalizer"
)

type customRule struct {}

func (rule *customRule) ProcessUsername(username string) string {
	return strings.Replace(username, "-", "", -1)
}

func (rule *customRule) ProcessDomain(domain string) string {
	return domain
}

func main() {
	n := normalizer.NewNormalizer()
	fmt.Println(n.Normalize("vasya+pupkin@gmail.com")) // vasya@gmail.com
	fmt.Println(n.Normalize("t.e-St+vasya@gmail.com")) // te-st@gmail.com
	fmt.Println(n.Normalize("t.e-St+@googlemail.com")) // te-st@gmail.com
	fmt.Println(n.Normalize("t.e-St+@google.com")) // te-st@gmail.com
	
	n.AddRule("customrules.com", &customRule{})
	fmt.Println(n.Normalize(" tE-S-t@CustomRules.com.")) // tESt@customrules.com
}

Supported providers

  • Apple
  • Fastmail
  • Google
  • Microsoft
  • Protonmail
  • Rackspace
  • Rambler
  • Yahoo
  • Yandex
  • Zoho

Also you can integrate another rules using AddRule function (see an example above)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppleRule added in v1.1.0

type AppleRule struct {
}

AppleRule : email normalization rule for Apple

func (*AppleRule) ProcessDomain added in v1.1.5

func (rule *AppleRule) ProcessDomain(domain string) string

func (*AppleRule) ProcessUsername added in v1.1.5

func (rule *AppleRule) ProcessUsername(username string) string

type FastmailRule

type FastmailRule struct {
}

FastmailRule : email normalization rule for Fastmail

func (*FastmailRule) ProcessDomain added in v1.1.5

func (rule *FastmailRule) ProcessDomain(domain string) string

func (*FastmailRule) ProcessUsername added in v1.1.5

func (rule *FastmailRule) ProcessUsername(username string) string

type GoogleRule

type GoogleRule struct {
}

GoogleRule : email normalization rule for Google

func (*GoogleRule) ProcessDomain added in v1.1.5

func (rule *GoogleRule) ProcessDomain(domain string) string

func (*GoogleRule) ProcessUsername added in v1.1.5

func (rule *GoogleRule) ProcessUsername(username string) string

type MicrosoftRule

type MicrosoftRule struct {
}

MicrosoftRule : email normalization rule for Microsoft

func (*MicrosoftRule) ProcessDomain added in v1.1.5

func (rule *MicrosoftRule) ProcessDomain(domain string) string

func (*MicrosoftRule) ProcessUsername added in v1.1.5

func (rule *MicrosoftRule) ProcessUsername(username string) string

type Normalizer

type Normalizer struct {
	// contains filtered or unexported fields
}

Normalizer : main library object for normalization emails

func NewNormalizer

func NewNormalizer() *Normalizer

NewNormalizer : creates Normalizer instance

func (*Normalizer) AddRule

func (n *Normalizer) AddRule(domain string, strategy NormalizingRule)

AddRule : appends custom normalization rule

func (*Normalizer) Normalize

func (n *Normalizer) Normalize(email string) string

Normalize : converts email to canonical form

type NormalizingRule

type NormalizingRule interface {
	ProcessUsername(string) string
	ProcessDomain(string) string
}

NormalizingRule : interface for all email normalization rules

type ProtonmailRule added in v1.1.0

type ProtonmailRule struct {
}

ProtonmailRule : email normalization rule for Protonmail

func (*ProtonmailRule) ProcessDomain added in v1.1.5

func (rule *ProtonmailRule) ProcessDomain(domain string) string

func (*ProtonmailRule) ProcessUsername added in v1.1.5

func (rule *ProtonmailRule) ProcessUsername(username string) string

type RackspaceRule added in v1.1.0

type RackspaceRule struct {
}

RackspaceRule : email normalization rule for Rackspace

func (*RackspaceRule) ProcessDomain added in v1.1.5

func (rule *RackspaceRule) ProcessDomain(domain string) string

func (*RackspaceRule) ProcessUsername added in v1.1.5

func (rule *RackspaceRule) ProcessUsername(username string) string

type RamblerRule

type RamblerRule struct {
}

RamblerRule : email normalization rule for Rambler

func (*RamblerRule) ProcessDomain added in v1.1.5

func (rule *RamblerRule) ProcessDomain(domain string) string

func (*RamblerRule) ProcessUsername added in v1.1.5

func (rule *RamblerRule) ProcessUsername(username string) string

type YahooRule added in v1.1.0

type YahooRule struct {
}

YahooRule : email normalization rule for Yahoo

func (*YahooRule) ProcessDomain added in v1.1.5

func (rule *YahooRule) ProcessDomain(domain string) string

func (*YahooRule) ProcessUsername added in v1.1.5

func (rule *YahooRule) ProcessUsername(username string) string

type YandexRule added in v1.1.0

type YandexRule struct {
}

YandexRule : email normalization rule for Yandex

func (*YandexRule) ProcessDomain added in v1.1.5

func (rule *YandexRule) ProcessDomain(domain string) string

func (*YandexRule) ProcessUsername added in v1.1.5

func (rule *YandexRule) ProcessUsername(username string) string

type ZohoRule added in v1.1.0

type ZohoRule struct {
}

ZohoRule : email normalization rule for Zoho

func (*ZohoRule) ProcessDomain added in v1.1.5

func (rule *ZohoRule) ProcessDomain(domain string) string

func (*ZohoRule) ProcessUsername added in v1.1.5

func (rule *ZohoRule) ProcessUsername(username string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL