// NewMessageFilter creates a new filter that can be used to poll for
// (new) messages that satisfy the given criteria.
482763
func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error) {
	var (
		src     *ecdsa.PublicKey
		keySym  []byte
		keyAsym *ecdsa.PrivateKey
		topics  [][]byte

		symKeyGiven  = len(req.SymKeyID) > 0
		asymKeyGiven = len(req.PrivateKeyID) > 0

		err error
	)

	// user must specify either a symmetric or an asymmetric key
	if (symKeyGiven && asymKeyGiven) || (!symKeyGiven && !asymKeyGiven) {
		return "", ErrSymAsym
	}

	if len(req.Sig) > 0 {
		if src, err = crypto.UnmarshalPubkey(req.Sig); err != nil {
			return "", ErrInvalidSigningPubKey
		}
	}

	if symKeyGiven {
		if keySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
			return "", err
		}
		if !validateDataIntegrity(keySym, aesKeyLength) {
			return "", ErrInvalidSymmetricKey
		}
	}

	if asymKeyGiven {
		if keyAsym, err = api.w.GetPrivateKey(req.PrivateKeyID); err != nil {
			return "", err
		}
	}

	if len(req.Topics) > 0 {
		topics = make([][]byte, len(req.Topics))
		for i, topic := range req.Topics {
			topics[i] = make([]byte, TopicLength)
			copy(topics[i], topic[:])
		}
	}

	f := &Filter{
		Src:      src,
		KeySym:   keySym,
		KeyAsym:  keyAsym,
		PoW:      req.MinPow,
		AllowP2P: req.AllowP2P,
		Topics:   topics,
		Messages: make(map[common.Hash]*ReceivedMessage),
	}

	id, err := api.w.Subscribe(f)
	if err != nil {
		return "", err
	}

	api.mu.Lock()
	api.lastUsed[id] = time.Now()
	api.mu.Unlock()

	return id, nil
}
562645
func NewMessageTemplate(m *Message) *MessageTemplate {
	pluralTemplates := map[plural.Form]*Template{}
	setPluralTemplate(pluralTemplates, plural.Zero, m.Zero)
	setPluralTemplate(pluralTemplates, plural.One, m.One)
	setPluralTemplate(pluralTemplates, plural.Two, m.Two)
	setPluralTemplate(pluralTemplates, plural.Few, m.Few)
	setPluralTemplate(pluralTemplates, plural.Many, m.Many)
	setPluralTemplate(pluralTemplates, plural.Other, m.Other)
	if len(pluralTemplates) == 0 {
		return nil
	}
	return &MessageTemplate{
		Message:         m,
		PluralTemplates: pluralTemplates,
	}
}
515536
func (m *Message) PartsFilter(filter func(*Message) bool) []*Message {

	messages := make([]*Message, 0, 1)
	if m.HasParts() {
		for _, part := range m.Parts {
			if filter(part) {
				messages = append(messages, part)
			}
		}
	}
	return messages
}
160161
func NewMessageFrom(to []string, from, subject, htmlBody string) *Message {
	log.Trace("NewMessageFrom (htmlBody):\n%s", htmlBody)

	msg := gomail.NewMessage()
	msg.SetHeader("From", from)
	msg.SetHeader("To", to...)
	msg.SetHeader("Subject", setting.MailService.SubjectPrefix+subject)
	msg.SetDateHeader("Date", time.Now())

	contentType := "text/html"
	body := htmlBody
	switchedToPlaintext := false
	if setting.MailService.UsePlainText || setting.MailService.AddPlainTextAlt {
		plainBody, err := html2text.FromString(htmlBody)
		if err != nil {
			log.Error(2, "html2text.FromString: %v", err)
		} else {
			contentType = "text/plain"
			body = plainBody
			switchedToPlaintext = true
		}
	}
	msg.SetBody(contentType, body)
	if switchedToPlaintext && setting.MailService.AddPlainTextAlt && !setting.MailService.UsePlainText {
		// The AddAlternative method name is confusing - adding html as an "alternative" will actually cause mail 
		// clients to show it as first priority, and the text "main body" is the 2nd priority fallback.
		// See: https://godoc.org/gopkg.in/gomail.v2#Message.AddAlternative
		msg.AddAlternative("text/html", htmlBody)
	}
	return &Message{
		Message:     msg,
		confirmChan: make(chan struct{}),
	}
}
713889
func NewMsgGetCFilters(filterType FilterType, startHeight uint32,
	stopHash *chainhash.Hash) *MsgGetCFilters {
	return &MsgGetCFilters{
		FilterType:  filterType,
		StartHeight: startHeight,
		StopHash:    *stopHash,
	}
}
404435
func (filter *None) ApplyFilter(msg *core.Message) (core.FilterResult, error) {
	return filter.GetFilterResultMessageReject(), nil
}
1030907
func (fw *Framework) NewRequestFromMessage(version string, msg *Message) (req protocol.Request, err error) {
	if !(msg.Type() == "request" || msg.Type() == "direct_request") {
		err = fmt.Errorf("Cannot use `%s` message to construct a Request", msg.Type())
		return
	}

	req, err = fw.NewRequest(version, msg.Agent, msg.SenderID, msg.CallerID, msg.TTL, msg.RequestID, msg.Collective())
	if err != nil {
		return req, fmt.Errorf("Could not create a Request from a Message: %s", err)
	}

	req.SetMessage(msg.Payload)

	if msg.Filter == nil || msg.Filter.Empty() {
		req.NewFilter()
	} else {
		req.SetFilter(msg.Filter)
	}

	return
}
368060
func NewDefaultMessage(p level.Priority, message string) Composer {
	m := &stringMessage{
		Message: message,
	}

	_ = m.SetPriority(p)

	return m
}
897824
func NewImageMessage(originalContentURL, previewImageURL string) *ImageMessage {
	return &ImageMessage{
		OriginalContentURL: originalContentURL,
		PreviewImageURL:    previewImageURL,
	}
}
678808
func NewMessage(seqNum uint32, items []FetchItem) *Message {
	msg := &Message{
		SeqNum:     seqNum,
		Items:      make(map[FetchItem]interface{}),
		Body:       make(map[*BodySectionName]Literal),
		itemsOrder: items,
	}

	for _, k := range items {
		msg.Items[k] = nil
	}

	return msg
}
105793
func NewMsg(code byte, name string, payload []byte) *Msg {
	return &Msg{
		Code:       code,
		Name:       []byte(name),
		Payload:    payload,
		namestring: name,
	}
}
830763
func (wc *WhisperClient) DeleteMessageFilter(ctx *Context, id string) error {
	return wc.client.DeleteMessageFilter(ctx.context, id)
}
1145951
func NewMessage(data interface{}) (*Message, error) {
	m := &Message{}
	if err := m.unmarshalInterface(data); err != nil {
		return nil, err
	}
	return m, nil
}
246854
func NewRunMessage(statement string, parameters map[string]interface{}) RunMessage {
	return RunMessage{
		statement:  statement,
		parameters: parameters,
	}
}
884572
func (this *FcmClient) NewFcmRegIdsMsg(list []string, body interface{}) *FcmClient {
	this.newDevicesList(list)
	this.Message.Data = body

	return this

}
214271
func NewMessage(sz int) *Message {
	var m *Message
	for i := range messageCache {
		if sz < messageCache[i].maxbody {
			m = messageCache[i].pool.Get().(*Message)
			break
		}
	}
	if m == nil {
		m = newMsg(sz)
	}

	m.refcnt = 1
	m.Body = m.bbuf
	m.Header = m.hbuf
	return m
}
246882
func newMessage(verb messageVerb, sender *Node, senderHeartbeat uint32) message {
	return message{
		sender:          sender,
		senderHeartbeat: senderHeartbeat,
		verb:            verb,
	}
}