Index: pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 3020)
+++ pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 3021)
@@ -102,5 +102,4 @@
     unsigned		    auto_answer;
     unsigned		    duration;
-    pj_bool_t		    unsolicited_mwi;
 
 #ifdef STEREO_DEMO
@@ -146,5 +145,4 @@
 static pj_status_t create_ipv6_media_transports(void);
 pj_status_t app_destroy(void);
-static void enable_unsolicited_mwi(void);
 
 static void ringback_start(pjsua_call_id call_id);
@@ -197,5 +195,4 @@
     puts  ("  --publish           Send presence PUBLISH for this account");
     puts  ("  --mwi               Subscribe to message summary/waiting indication");
-    puts  ("  --unsolicited-mwi   Handle unsolicited MWI requests");
     puts  ("  --use-100rel        Require reliable provisional response (100rel)");
     puts  ("  --use-timer         Require SIP session timers");
@@ -488,5 +485,5 @@
 	   OPT_BOUND_ADDR, OPT_CONTACT_PARAMS, OPT_CONTACT_URI_PARAMS,
 	   OPT_100REL, OPT_USE_IMS, OPT_REALM, OPT_USERNAME, OPT_PASSWORD,
-	   OPT_MWI, OPT_UNSOLICITED_MWI, OPT_NAMESERVER, OPT_STUN_SRV,
+	   OPT_MWI, OPT_NAMESERVER, OPT_STUN_SRV,
 	   OPT_ADD_BUDDY, OPT_OFFER_X_MS_MSG, OPT_NO_PRESENCE,
 	   OPT_AUTO_ANSWER, OPT_AUTO_PLAY, OPT_AUTO_PLAY_HANGUP, OPT_AUTO_LOOP,
@@ -541,5 +538,4 @@
 	{ "publish",    0, 0, OPT_PUBLISH},
 	{ "mwi",	0, 0, OPT_MWI},
-	{ "unsolicited-mwi", 0, 0, OPT_UNSOLICITED_MWI},
 	{ "use-100rel", 0, 0, OPT_100REL},
 	{ "use-ims",    0, 0, OPT_USE_IMS},
@@ -844,8 +840,4 @@
 	    break;
 
-	case OPT_UNSOLICITED_MWI:
-	    cfg->unsolicited_mwi = PJ_TRUE;
-	    break;
-
 	case OPT_100REL: /** 100rel */
 	    cur_acc->require_100rel = PJ_TRUE;
@@ -1999,8 +1991,4 @@
     {
 	pj_strcat2(&cfg, "--use-compact-form\n");
-    }
-
-    if (config->unsolicited_mwi) {
-	pj_strcat2(&cfg, "--unsolicited-mwi\n");
     }
 
@@ -4408,8 +4396,4 @@
 	return status;
 
-    /* Initialize unsolicited MWI */
-    if (app_config.unsolicited_mwi)
-	enable_unsolicited_mwi();
-
     /* Initialize our module to handle otherwise unhandled request */
     status = pjsip_endpt_register_module(pjsua_get_pjsip_endpt(),
@@ -5016,87 +5000,2 @@
 }
 
-/*****************************************************************************
- * Asterisk unsolicited MWI module
- */
-static pj_bool_t mwi_on_rx_request(pjsip_rx_data *rdata)
-{
-    pjsip_msg *msg = rdata->msg_info.msg;
-    pj_str_t EVENT_HDR  = { "Event", 5 };
-    pj_str_t MWI = { "message-summary", 15 };
-    pjsip_event_hdr *eh;
-    pj_str_t body;
-
-    if (pjsip_method_cmp(&msg->line.req.method, &pjsip_notify_method)!=0) {
-	/* Only interested with NOTIFY request */
-	return PJ_FALSE;
-    }
-
-    eh = (pjsip_event_hdr*) pjsip_msg_find_hdr_by_name(msg, &EVENT_HDR, NULL);
-    if (!eh) {
-	/* Something wrong with the request, it has no Event hdr */
-	return PJ_FALSE;
-    }
-
-    if (pj_stricmp(&eh->event_type, &MWI) != 0) {
-	/* Not MWI event */
-	return PJ_FALSE;
-    }
-
-    /* Got unsolicited MWI request, respond with 200/OK first */
-    pjsip_endpt_respond(pjsua_get_pjsip_endpt(), NULL, rdata, 200, NULL,
-			NULL, NULL, NULL);
-
-
-    PJ_LOG(3,(THIS_FILE, "Received MWI info:"));
-
-    if (rdata->msg_info.ctype) {
-	const pjsip_ctype_hdr *ctype = rdata->msg_info.ctype;
-
-	PJ_LOG(3,(THIS_FILE, " Content-Type: %.*s/%.*s",
-	          (int)ctype->media.type.slen,
-		  ctype->media.type.ptr,
-		  (int)ctype->media.subtype.slen,
-		  ctype->media.subtype.ptr));
-    }
-
-    if (!rdata->msg_info.msg->body) {
-	PJ_LOG(3,(THIS_FILE, "  no message body"));
-	return PJ_TRUE;
-    }
-
-    body.ptr = rdata->msg_info.msg->body->data;
-    body.slen = rdata->msg_info.msg->body->len;
-
-    PJ_LOG(3,(THIS_FILE, " Body:\n%.*s", (int)body.slen, body.ptr));
-    
-    return PJ_TRUE;
-}
-
-/* The module instance. */
-static pjsip_module pjsua_mwi_mod = 
-{
-    NULL, NULL,				/* prev, next.		*/
-    { "mod-unsolicited-mwi", 19 },	/* Name.		*/
-    -1,					/* Id			*/
-    PJSIP_MOD_PRIORITY_UA_PROXY_LAYER-1,/* Priority	        */
-    NULL,				/* load()		*/
-    NULL,				/* start()		*/
-    NULL,				/* stop()		*/
-    NULL,				/* unload()		*/
-    &mwi_on_rx_request,			/* on_rx_request()	*/
-    NULL,				/* on_rx_response()	*/
-    NULL,				/* on_tx_request.	*/
-    NULL,				/* on_tx_response()	*/
-    NULL,				/* on_tsx_state()	*/
-};
-
-static void enable_unsolicited_mwi(void)
-{
-    pj_status_t status;
-
-    status = pjsip_endpt_register_module(pjsua_get_pjsip_endpt(), 
-					 &pjsua_mwi_mod);
-    if (status != PJ_SUCCESS)
-	pjsua_perror(THIS_FILE, "Error registering MWI module", status);
-}
-
Index: pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 3020)
+++ pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 3021)
@@ -1003,4 +1003,19 @@
 
     /**
+     * Handle unsolicited NOTIFY requests containing message waiting 
+     * indication (MWI) info. Unsolicited MWI is incoming NOTIFY requests 
+     * which are not requested by client with SUBSCRIBE request. 
+     *
+     * If this is enabled, the library will respond 200/OK to the NOTIFY
+     * request and forward the request to \a on_mwi_info() callback.
+     *
+     * See also \a mwi_enabled field #on pjsua_acc_config.
+     *
+     * Default: PJ_TRUE
+     *
+     */
+    pj_bool_t	    enable_unsolicited_mwi;
+
+    /**
      * Specify Session Timer settings, see #pjsip_timer_setting. 
      * Note that this setting can be further customized in account 
@@ -1883,6 +1898,7 @@
 
     /**
-     * Enable message summary and message waiting indication subscription
-     * (RFC 3842) for this account.
+     * Subscribe to message waiting indication events (RFC 3842).
+     *
+     * See also \a enable_unsolicited_mwi field on #pjsua_config.
      *
      * Default: no
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 3020)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 3021)
@@ -102,4 +102,5 @@
     cfg->stun_ignore_failure = PJ_TRUE;
     cfg->force_lr = PJ_TRUE;
+    cfg->enable_unsolicited_mwi = PJ_TRUE;
 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
     cfg->use_srtp = PJSUA_DEFAULT_USE_SRTP;
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 3020)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 3021)
@@ -2076,4 +2076,85 @@
 
 
+/***************************************************************************
+ * Unsolicited MWI
+ */
+static pj_bool_t unsolicited_mwi_on_rx_request(pjsip_rx_data *rdata)
+{
+    pjsip_msg *msg = rdata->msg_info.msg;
+    pj_str_t EVENT_HDR  = { "Event", 5 };
+    pj_str_t MWI = { "message-summary", 15 };
+    pjsip_event_hdr *eh;
+
+    if (pjsip_method_cmp(&msg->line.req.method, &pjsip_notify_method)!=0) {
+	/* Only interested with NOTIFY request */
+	return PJ_FALSE;
+    }
+
+    eh = (pjsip_event_hdr*) pjsip_msg_find_hdr_by_name(msg, &EVENT_HDR, NULL);
+    if (!eh) {
+	/* Something wrong with the request, it has no Event hdr */
+	return PJ_FALSE;
+    }
+
+    if (pj_stricmp(&eh->event_type, &MWI) != 0) {
+	/* Not MWI event */
+	return PJ_FALSE;
+    }
+
+    /* Got unsolicited MWI request, respond with 200/OK first */
+    pjsip_endpt_respond(pjsua_get_pjsip_endpt(), NULL, rdata, 200, NULL,
+			NULL, NULL, NULL);
+
+
+    /* Call callback */
+    if (pjsua_var.ua_cfg.cb.on_mwi_info) {
+	pjsua_acc_id acc_id;
+	pjsua_mwi_info mwi_info;
+
+	acc_id = pjsua_acc_find_for_incoming(rdata);
+
+	pj_bzero(&mwi_info, sizeof(mwi_info));
+	mwi_info.rdata = rdata;
+
+	(*pjsua_var.ua_cfg.cb.on_mwi_info)(acc_id, &mwi_info);
+    }
+
+    
+    return PJ_TRUE;
+}
+
+/* The module instance. */
+static pjsip_module pjsua_unsolicited_mwi_mod = 
+{
+    NULL, NULL,				/* prev, next.		*/
+    { "mod-unsolicited-mwi", 19 },	/* Name.		*/
+    -1,					/* Id			*/
+    PJSIP_MOD_PRIORITY_APPLICATION,	/* Priority	        */
+    NULL,				/* load()		*/
+    NULL,				/* start()		*/
+    NULL,				/* stop()		*/
+    NULL,				/* unload()		*/
+    &unsolicited_mwi_on_rx_request,	/* on_rx_request()	*/
+    NULL,				/* on_rx_response()	*/
+    NULL,				/* on_tx_request.	*/
+    NULL,				/* on_tx_response()	*/
+    NULL,				/* on_tsx_state()	*/
+};
+
+static pj_status_t enable_unsolicited_mwi(void)
+{
+    pj_status_t status;
+
+    status = pjsip_endpt_register_module(pjsua_get_pjsip_endpt(), 
+					 &pjsua_unsolicited_mwi_mod);
+    if (status != PJ_SUCCESS)
+	pjsua_perror(THIS_FILE, "Error registering unsolicited MWI module", 
+		     status);
+
+    return status;
+}
+
+
+
 /***************************************************************************/
 
@@ -2151,4 +2232,10 @@
     }
 
+    if (pjsua_var.ua_cfg.enable_unsolicited_mwi) {
+	pj_status_t status = enable_unsolicited_mwi();
+	if (status != PJ_SUCCESS)
+	    return status;
+    }
+
     return PJ_SUCCESS;
 }
