Exemplo n.º 1
0
static void
vacation_subject (mu_sieve_machine_t mach, mu_list_t tags,
		  mu_message_t msg, mu_header_t newhdr)
{
  mu_sieve_value_t *arg;
  char *value;
  char *subject;
  int subject_allocated = 0;
  mu_header_t hdr;
  
  if (mu_sieve_tag_lookup (tags, "subject", &arg))
    subject =  arg->v.string;
  else if (mu_message_get_header (msg, &hdr) == 0
	   && mu_header_aget_value_unfold (hdr, MU_HEADER_SUBJECT,
					   &value) == 0)
    {
      char *p;
      
      int rc = mu_rfc2047_decode (MU_SIEVE_CHARSET, value, &p);

      subject_allocated = 1;
      if (rc)
	{
	  subject = value;
	  value = NULL;
	}
      else
	{
	  subject = p;
	}

      if (mu_sieve_tag_lookup (tags, "reply_regex", &arg))
	{
	  char *err = NULL;
	  
	  rc = mu_unre_set_regex (arg->v.string, 0, &err);
	  if (rc)
	    {
	      mu_sieve_error (mach,
			      _("%lu: cannot compile reply prefix regexp: %s: %s"),
			      (unsigned long) mu_sieve_get_message_num (mach),
			      mu_strerror (rc),
			      err ? err : "");
	    }
	}
	  
      if (mu_unre_subject (subject, NULL))
	re_subject (mach, tags, &subject);
      
      free (value);
    }
  else
    subject = "Re: Your mail";
    
  if (mu_rfc2047_encode (MU_SIEVE_CHARSET, "quoted-printable",
			 subject, &value))
    mu_header_set_value (newhdr, MU_HEADER_SUBJECT, subject, 0);
  else
    {
      mu_header_set_value (newhdr, MU_HEADER_SUBJECT, value, 0);
      free (value);
    }

  if (subject_allocated)
    free (subject);
}
Exemplo n.º 2
0
int
reply0 (msgset_t *mspec, mu_message_t msg, void *data)
{
  mu_header_t hdr;
  compose_env_t env;
  int status;
  char *str;

  set_cursor (mspec->msg_part[0]);
  
  compose_init (&env);

  mu_message_get_header (msg, &hdr);

  compose_header_set (&env, MU_HEADER_TO,
		      util_get_sender (mspec->msg_part[0], 0),
		      COMPOSE_SINGLE_LINE);

  if (*(int*) data) /* reply starts with a lowercase */
    {
      /* Add all recepients of the originate letter */

      mu_address_t addr = NULL;
      size_t i, count = 0;

      if (mu_header_aget_value (hdr, MU_HEADER_TO, &str) == 0)
	{
	  mu_address_create (&addr, str);
	  free (str);
	  mu_address_get_count (addr, &count);
	}

      /* Make sure we do not include our alternate names */
      for (i = 1; i <= count; i++)
	{
	  const char *email;
	  if (mu_address_sget_email (addr, i, &email) || email == NULL)
	    continue;
	  if ((mailvar_get (NULL, "metoo", mailvar_type_boolean, 0) == 0)
	      || !mail_is_my_name (email))
	    compose_header_set (&env, MU_HEADER_TO,
				email,
				COMPOSE_SINGLE_LINE);
	}
      
      mu_address_destroy (&addr);

      /* Finally, add any Ccs */
      if (mu_header_aget_value (hdr, MU_HEADER_CC, &str) == 0)
	compose_header_set (&env, MU_HEADER_TO, str, COMPOSE_SINGLE_LINE);
    }

  if (mu_header_aget_value (hdr, MU_HEADER_SUBJECT, &str) == 0)
    {
      char *p = NULL;
      
      if (mu_unre_subject (str, NULL))
	util_strcat (&p, util_reply_prefix ());
      util_strcat (&p, str);
      free (str);
      compose_header_set (&env, MU_HEADER_SUBJECT, p, COMPOSE_REPLACE);
      free (p);
    }
  else
    compose_header_set (&env, MU_HEADER_SUBJECT, "", COMPOSE_REPLACE);

  mu_printf ("To: %s\n",
	   compose_header_get (&env, MU_HEADER_TO, ""));
  str = compose_header_get (&env, MU_HEADER_CC, NULL);
  if (str)
    mu_printf ("Cc: %s\n", str);
  mu_printf ("Subject: %s\n\n",
		    compose_header_get (&env, MU_HEADER_SUBJECT, ""));
  
  make_in_reply_to (&env, msg);
  make_references (&env, msg);
  status = mail_send0 (&env,
		       mailvar_get (NULL, "byname", mailvar_type_boolean, 0)
		                     == 0);
  compose_destroy (&env);

  return status;
}