Exemplo n.º 1
0
func (milter *milter) Eom(ctx uintptr) (sfsistat int8) {
	defer milterHandleError(ctx, &sfsistat)

	s := milterGetSession(ctx, true, false)
	StatsCounters["MilterCallbackEom"].increase(1)
	Log.Debug("%s milter.Eom() was called", s.milterGetDisplayId())

	verdict, msg, results := messageGetVerdict(s.getLastMessage())
	headersAdd, headersDelete := messageGetMutableHeaders(s.getLastMessage(), results)
	for _, hdr := range headersDelete {
		var delete string // Must be null to delete
		m.ChgHeader(ctx, hdr.getKey(), hdr.milterIdx, delete)
		hdr.deleted = true

		for _, allHdr := range s.getLastMessage().GetHeader(hdr.getKey(), false) {
			if allHdr.milterIdx > hdr.milterIdx {
				allHdr.milterIdx = allHdr.milterIdx - 1
			}
		}
	}

	for _, hdr := range headersAdd {
		m.AddHeader(ctx, hdr.getKey(), hdr.getValue())
	}

	if s.isWhitelisted() {
		verdict = messagePermit
		msg = "Whitelisted"
	}

	switch {
	case verdict == messagePermit:
		Log.Info("Message Permit: sess=%s message=%s %s", s.milterGetDisplayId(), s.getLastMessage().QueueId, msg)
		return
	case verdict == messageTempFail:
		m.SetReply(ctx, "421", "4.7.0", msg)
		Log.Info("Message TempFail: sess=%s message=%s msg: %s", s.milterGetDisplayId(), s.getLastMessage().QueueId, msg)
		if Config.ClueGetter.Noop {
			return
		}
		return m.Tempfail
	case verdict == messageReject:
		m.SetReply(ctx, "550", "5.7.1", msg)
		Log.Info("Message Reject: sess=%s message=%s msg: %s", s.milterGetDisplayId(), s.getLastMessage().QueueId, msg)
		if Config.ClueGetter.Noop {
			return
		}
		return m.Reject
	}

	panic("verdict was not recognized")
}
Exemplo n.º 2
0
func (milter *milter) Eom(ctx uintptr) (sfsistat int8) {
	defer milterHandleError(ctx, &sfsistat)

	s := milterGetSession(ctx, true, false)
	StatsCounters["MilterCallbackEom"].increase(1)
	Log.Debug("%d milter.Eom() was called", s.getId())

	verdict, msg, results := messageGetVerdict(s.getLastMessage())
	for _, hdr := range messageGetHeadersToAdd(s.getLastMessage(), results) {
		m.AddHeader(ctx, hdr.getKey(), hdr.getValue())
	}

	if s.isWhitelisted() {
		verdict = messagePermit
		msg = "Whitelisted"
	}

	switch {
	case verdict == messagePermit:
		Log.Info("Message Permit: sess=%d message=%s %s", s.getId(), s.getLastMessage().getQueueId(), msg)
		return
	case verdict == messageTempFail:
		m.SetReply(ctx, "421", "4.7.0", msg)
		Log.Info("Message TempFail: sess=%d message=%s msg: %s", s.getId(), s.getLastMessage().getQueueId(), msg)
		if Config.ClueGetter.Noop {
			return
		}
		return m.Tempfail
	case verdict == messageReject:
		m.SetReply(ctx, "550", "5.7.1", msg)
		Log.Info("Message Reject: sess=%d message=%s msg: %s", s.getId(), s.getLastMessage().getQueueId(), msg)
		if Config.ClueGetter.Noop {
			return
		}
		return m.Reject
	}

	panic("verdict was not recognized")
}
Exemplo n.º 3
0
func milterHandleError(ctx uintptr, sfsistat *int8) {
	if Config.ClueGetter.Exit_On_Panic {
		return
	}
	r := recover()
	if r == nil {
		return
	}

	Log.Error("Panic ocurred while handling milter communication. Recovering. Error: %s", r)
	StatsCounters["MessagePanics"].increase(1)
	if Config.ClueGetter.Noop {
		return
	}

	s := milterGetSession(ctx, true, true)
	if s != nil && s.isWhitelisted() {
		return
	}

	m.SetReply(ctx, "421", "4.7.0", "An internal error ocurred")
	*sfsistat = m.Tempfail
	return
}