Index: /pjproject/trunk/pjsip/include/pjsip/sip_config.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsip/sip_config.h	(revision 4171)
+++ /pjproject/trunk/pjsip/include/pjsip/sip_config.h	(revision 4172)
@@ -995,4 +995,21 @@
 
 
+/**
+ * Specify the default expiration time for Message Waiting Indication
+ * (RFC 3842) event subscription, for both client and server subscription.
+ * For client subscription, application can override this by specifying
+ * positive non-zero value in "expires" parameter when calling
+ * #pjsip_mwi_initiate(). For server subscription, we would take the
+ * expiration value from the Expires header sent by client in the SUBSCRIBE
+ * request if the header exists and its value is less than  this setting,
+ * otherwise this setting will be used.
+ *
+ * Default: 3600 seconds
+ */
+#ifndef PJSIP_MWI_DEFAULT_EXPIRES
+#   define PJSIP_MWI_DEFAULT_EXPIRES		3600
+#endif
+
+
 PJ_END_DECL
 
Index: /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4171)
+++ /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4172)
@@ -2616,4 +2616,12 @@
 
     /**
+     * Specify the default expiration time for Message Waiting Indication
+     * (RFC 3842) event subscription. This must not be zero.
+     *
+     * Default: PJSIP_MWI_DEFAULT_EXPIRES
+     */
+    unsigned	    mwi_expires;
+
+    /**
      * If this flag is set, the presence information of this account will
      * be PUBLISH-ed to the server where the account belongs.
Index: /pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 4171)
+++ /pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 4172)
@@ -671,5 +671,5 @@
  * Start MWI subscription
  */
-void pjsua_start_mwi(pjsua_acc *acc);
+pj_status_t pjsua_start_mwi(pjsua_acc_id acc_id, pj_bool_t force_renew);
 
 /**
Index: /pjproject/trunk/pjsip/src/pjsip-simple/mwi.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip-simple/mwi.c	(revision 4171)
+++ /pjproject/trunk/pjsip/src/pjsip-simple/mwi.c	(revision 4172)
@@ -33,5 +33,4 @@
 
 #define THIS_FILE		    "mwi.c"
-#define MWI_DEFAULT_EXPIRES	    3600
 
  /*
@@ -139,5 +138,5 @@
     /* Register event package to event module. */
     status = pjsip_evsub_register_pkg( &mod_mwi, &STR_MWI, 
-				       MWI_DEFAULT_EXPIRES, 
+				       PJSIP_MWI_DEFAULT_EXPIRES, 
 				       PJ_ARRAY_SIZE(accept), accept);
     if (status != PJ_SUCCESS) {
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 4171)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 4172)
@@ -470,5 +470,5 @@
 	/* Otherwise subscribe to MWI, if it's enabled */
 	if (pjsua_var.acc[id].cfg.mwi_enabled)
-	    pjsua_start_mwi(&pjsua_var.acc[id]);
+	    pjsua_start_mwi(id, PJ_TRUE);
     }
 
@@ -680,4 +680,5 @@
     pj_bool_t update_reg = PJ_FALSE;
     pj_bool_t unreg_first = PJ_FALSE;
+    pj_bool_t update_mwi = PJ_FALSE;
     pj_status_t status = PJ_SUCCESS;
 
@@ -839,5 +840,12 @@
 
     /* MWI */
-    acc->cfg.mwi_enabled = cfg->mwi_enabled;
+    if (acc->cfg.mwi_enabled != cfg->mwi_enabled) {
+	acc->cfg.mwi_enabled = cfg->mwi_enabled;
+	update_mwi = PJ_TRUE;
+    }
+    if (acc->cfg.mwi_expires != cfg->mwi_expires && cfg->mwi_expires > 0) {
+	acc->cfg.mwi_expires = cfg->mwi_expires;
+	update_mwi = PJ_TRUE;
+    }
 
     /* PIDF tuple ID */
@@ -1133,9 +1141,9 @@
 	if (acc->cfg.reg_uri.slen)
 	    pjsua_acc_set_registration(acc->index, PJ_TRUE);
-	else {
-	    /* Otherwise subscribe to MWI, if it's enabled */
-	    if (acc->cfg.mwi_enabled)
-		pjsua_start_mwi(acc);
-	}
+    }
+
+    /* Update MWI subscription */
+    if (update_mwi) {
+	pjsua_start_mwi(acc_id, PJ_TRUE);
     }
 
@@ -1876,5 +1884,5 @@
 	    /* Subscribe to MWI, if it's enabled */
 	    if (acc->cfg.mwi_enabled)
-		pjsua_start_mwi(acc);
+		pjsua_start_mwi(acc->index, PJ_FALSE);
 	}
 
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 4171)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 4172)
@@ -238,4 +238,5 @@
     cfg->call_hold_type = PJSUA_CALL_HOLD_TYPE_DEFAULT;
     cfg->register_on_acc_add = PJ_TRUE;
+    cfg->mwi_expires = PJSIP_MWI_DEFAULT_EXPIRES;
 }
 
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 4171)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 4172)
@@ -2012,15 +2012,20 @@
 };
 
-void pjsua_start_mwi(pjsua_acc *acc)
-{
+pj_status_t pjsua_start_mwi(pjsua_acc_id acc_id, pj_bool_t force_renew)
+{
+    pjsua_acc *acc;
     pj_pool_t *tmp_pool = NULL;
     pj_str_t contact;
     pjsip_tx_data *tdata;
-    pj_status_t status;
+    pj_status_t status = PJ_SUCCESS;
+
+    PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc)
+                     && pjsua_var.acc[acc_id].valid, PJ_EINVAL);
+
+    acc = &pjsua_var.acc[acc_id];
 
     if (!acc->cfg.mwi_enabled) {
 	if (acc->mwi_sub) {
 	    /* Terminate MWI subscription */
-	    pjsip_tx_data *tdata;
 	    pjsip_evsub *sub = acc->mwi_sub;
 
@@ -2036,11 +2041,24 @@
 	    }
 	}
-	return;
-    }
-
+	return status;
+    }
+
+    /* Subscription is already active */
     if (acc->mwi_sub) {
-	/* Subscription is already active */
-	return;
-
+	if (!force_renew)
+	    return PJ_SUCCESS;
+	
+	/* Update MWI subscription */
+	pj_assert(acc->mwi_dlg);
+	pjsip_dlg_inc_lock(acc->mwi_dlg);
+	
+	status = pjsip_mwi_initiate(acc->mwi_sub, acc->cfg.mwi_expires, &tdata);
+	if (status == PJ_SUCCESS) {
+	    pjsua_process_msg_data(tdata, NULL);
+	    status = pjsip_pres_send_request(acc->mwi_sub, tdata);
+	}
+
+	pjsip_dlg_dec_lock(acc->mwi_dlg);
+	return status;
     }
 
@@ -2060,7 +2078,5 @@
 	    pjsua_perror(THIS_FILE, "Unable to generate Contact header", 
 		         status);
-	    pj_pool_release(tmp_pool);
-	    pj_log_pop_indent();
-	    return;
+	    goto on_return;
 	}
     }
@@ -2074,7 +2090,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create dialog", status);
-	if (tmp_pool) pj_pool_release(tmp_pool);
-	pj_log_pop_indent();
-	return;
+	goto on_return;
     }
 
@@ -2089,8 +2103,6 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Error creating MWI subscription", status);
-	if (tmp_pool) pj_pool_release(tmp_pool);
 	if (acc->mwi_dlg) pjsip_dlg_dec_lock(acc->mwi_dlg);
-	pj_log_pop_indent();
-	return;
+	goto on_return;
     }
 
@@ -2121,5 +2133,5 @@
     pjsip_evsub_set_mod_data(acc->mwi_sub, pjsua_var.mod.id, acc);
 
-    status = pjsip_mwi_initiate(acc->mwi_sub, -1, &tdata);
+    status = pjsip_mwi_initiate(acc->mwi_sub, acc->cfg.mwi_expires, &tdata);
     if (status != PJ_SUCCESS) {
 	if (acc->mwi_dlg) pjsip_dlg_dec_lock(acc->mwi_dlg);
@@ -2131,7 +2143,5 @@
 	pjsua_perror(THIS_FILE, "Unable to create initial MWI SUBSCRIBE", 
 		     status);
-	if (tmp_pool) pj_pool_release(tmp_pool);
-	pj_log_pop_indent();
-	return;
+	goto on_return;
     }
 
@@ -2148,13 +2158,14 @@
 	pjsua_perror(THIS_FILE, "Unable to send initial MWI SUBSCRIBE", 
 		     status);
-	if (tmp_pool) pj_pool_release(tmp_pool);
-	pj_log_pop_indent();
-	return;
+	goto on_return;
     }
 
     pjsip_dlg_dec_lock(acc->mwi_dlg);
+
+on_return:
     if (tmp_pool) pj_pool_release(tmp_pool);
 
     pj_log_pop_indent();
+    return status;
 }
 
@@ -2270,5 +2281,5 @@
 	/* Re-subscribe MWI subscription if it's terminated prematurely */
 	if (acc->cfg.mwi_enabled && !acc->mwi_sub)
-	    pjsua_start_mwi(acc);
+	    pjsua_start_mwi(acc->index, PJ_FALSE);
     }
 
