diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 7b541471ec..184af347d3 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -7510,12 +7510,17 @@ static int handle_request(struct sip_pvt *p, struct sip_request *req, struct soc p->needdestroy = 1; transmit_response(p, "200 OK", req); } else if (!strcasecmp(cmd, "MESSAGE")) { - if (!ignore) { - if (debug) - ast_verbose("Receiving message!\n"); - receive_message(p, req); + if (p->lastinvite) { + if (!ignore) { + if (debug) + ast_verbose("Receiving message!\n"); + receive_message(p, req); + } + transmit_response(p, "200 OK", req); + } else { + transmit_response(p, "405 Method Not Allowed", req); + p->needdestroy = 1; } - transmit_response(p, "200 OK", req); } else if (!strcasecmp(cmd, "SUBSCRIBE")) { if (!ignore) { /* Use this as the basis */