Nginx imap mail timeout

Hi

I have a nginx server configured to handle imap mail traffic. i want to
enforce the following

  1. if downstream email client does not send a command for more than 2
    mins, the nginx proxy should disconnect.

  2. if upstream server (real mail server) does not respond for more than
    5 mins or takes longer than 5 mins to respond, disconnect both upstream
    and downstream connections.

Does anyone have any ideas on doing this on nginx?

in ngx_mail_proxy_module.c i see

{ ngx_string("proxy_timeout"),
  NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
  ngx_conf_set_msec_slot,
  NGX_MAIL_SRV_CONF_OFFSET,
  offsetof(ngx_mail_proxy_conf_t, timeout),
  NULL },

and in ngx_mail_core_module.c

{ ngx_string("timeout"),
  NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
  ngx_conf_set_msec_slot,
  NGX_MAIL_SRV_CONF_OFFSET,
  offsetof(ngx_mail_core_srv_conf_t, timeout),
  NULL },

does anyone have any experience dealing with these or have any
suggestions?

thanks!