emailnormalizer

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 1 Imported by: 0

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/v2

Usage

package main

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

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+.-est@yahoo.com"))      // t+.est@yahoo.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 other 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

type AppleRule struct {
}

AppleRule : email normalization rule for Apple

func (*AppleRule) ProcessDomain

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

func (*AppleRule) ProcessUsername

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

type FastmailRule

type FastmailRule struct {
}

FastmailRule : email normalization rule for Fastmail

func (*FastmailRule) ProcessDomain

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

func (*FastmailRule) ProcessUsername

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

type GoogleRule

type GoogleRule struct {
}

GoogleRule : email normalization rule for Google

func (*GoogleRule) ProcessDomain

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

func (*GoogleRule) ProcessUsername

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

type MicrosoftRule

type MicrosoftRule struct {
}

MicrosoftRule : email normalization rule for Microsoft

func (*MicrosoftRule) ProcessDomain

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

func (*MicrosoftRule) ProcessUsername

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

type ProtonmailRule struct {
}

ProtonmailRule : email normalization rule for Protonmail

func (*ProtonmailRule) ProcessDomain

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

func (*ProtonmailRule) ProcessUsername

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

type RackspaceRule

type RackspaceRule struct {
}

RackspaceRule : email normalization rule for Rackspace

func (*RackspaceRule) ProcessDomain

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

func (*RackspaceRule) ProcessUsername

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

type RamblerRule

type RamblerRule struct {
}

RamblerRule : email normalization rule for Rambler

func (*RamblerRule) ProcessDomain

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

func (*RamblerRule) ProcessUsername

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

type YahooRule

type YahooRule struct {
}

YahooRule : email normalization rule for Yahoo

func (*YahooRule) ProcessDomain

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

func (*YahooRule) ProcessUsername

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

type YandexRule

type YandexRule struct {
}

YandexRule : email normalization rule for Yandex

func (*YandexRule) ProcessDomain

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

func (*YandexRule) ProcessUsername

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

type ZohoRule

type ZohoRule struct {
}

ZohoRule : email normalization rule for Zoho

func (*ZohoRule) ProcessDomain

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

func (*ZohoRule) ProcessUsername

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