Back to index

courier  0.68.2
Functions
autoresponse.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void autoresponse ()
void autoresponselist ()
void autoresponsedelete ()
void autoresponsepick ()

Function Documentation

void autoresponse ( )

Definition at line 62 of file autoresponse.c.

{
const char    *autoresp_title1=getarg("TITLE1");
const char    *autoresp_title2=getarg("TITLE2");
const char    *autoresp_text1=getarg("TEXT1");
const char    *autoresp_text2=getarg("TEXT2");

       if ( *cgi("do.newautoresp"))
       {
              const char *name=cgi("newname");
              char *p;
              FILE *fp;

              p=folder_toutf7(name);

              if (!p || maildir_autoresponse_validate(NULL, p))
              {
                     free(p);
                     printf("%s", getarg("BADNAME"));
                     return;
              }

              if ((fp=maildir_autoresponse_open(NULL, p)) != NULL)
              {
                     free(p);
                     fclose(fp);
                     printf("%s", getarg("EEXIST"));
                     return;
              }

              printf("%s%s%s\n", autoresp_title1, name, autoresp_title2);
              printf("<input type=\"hidden\" name=\"autoresponse\" value=\"");
              output_attrencoded(p);
              printf("\" />\n");
              free(p);

              printf("%s%s\n", autoresp_text1, autoresp_text2);
              printf("%s<input type=\"file\" size=\"20\" name=\"uploadfile\" /><br />",
                     getarg("UPLOAD"));
              printf("<input type=\"submit\" name=\"do.autorespcreate\""
                     " value=\"%s\" />", getarg("SAVE"));
              return;
       }

       if ( *cgi("do.autorespedit"))
       {
              const char *autorespname=cgi("autoresponse_choose");
              FILE *fp;
              char *s=folder_fromutf7(autorespname);
              const char *pp;

              if (!s)
              {
                     printf(getarg("ERROR"), strerror(errno));
                     return;
              }

              pp=cgi("replytext");

              if ((fp=maildir_autoresponse_open(NULL, autorespname)) == NULL
                  && !*pp)
              {
                     free(s);
                     return;
              }

              printf("%s%s%s\n", autoresp_title1, s, autoresp_title2);

              if (fp && read_headers(fp))
              {
                     fclose(fp);
                     free(s);
                     return;
              }

              printf("<input type=\"hidden\" name=\"autoresponse\" value=\"");
              output_attrencoded(autorespname);
              printf("\" />\n");
              free(s);

              printf("%s", autoresp_text1);

              if (pp && *pp)
                     output_attrencoded(pp);
              else
              {
                     struct show_textarea_info info;
                     libmail_u_convert_handle_t h;

                     show_textarea_init(&info, 0);

                     h=libmail_u_convert_init("utf-8",
                                           sqwebmail_content_charset,
                                           show_autoresponse_trampoline,
                                           &info);

                     if (h)
                     {
                            size_t i;
                            char buf[BUFSIZ];

                            while ((i=fread(buf, 1, sizeof(buf), fp)) > 0)
                            {
                                   libmail_u_convert(h, buf, i);
                            }
                            libmail_u_convert_deinit(h, NULL);
                     }
              }

              if (fp)
                     fclose(fp);
              printf("%s\n", autoresp_text2);
              printf("%s<input type=\"file\" size=\"20\" name=\"uploadfile\" /><br />",
                     getarg("UPLOAD"));
              printf("<input type=\"submit\" name=\"do.autorespcreate\""
                     " value=\"%s\" />", getarg("SAVE"));
              return;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 223 of file autoresponse.c.

{
       if ( *cgi("do.autorespcreate"))
       {
              const char *autorespname=cgi("autoresponse");
              const char *autoresptxt=cgi("text");
              FILE *fp;
              size_t l;

              if ((fp=upload_attachment(autorespname)) == NULL)
              {
                     struct wrap_info uw;

                     if ((fp=maildir_autoresponse_create(NULL,
                                                     autorespname))
                         == NULL)
                     {
                            printf(getarg("SAVEFAILED"), strerror(errno));
                            return;
                     }

                     l=strlen(autoresptxt);
                     while (l && (autoresptxt[l-1] == '\r' ||
                                 autoresptxt[l-1] == '\n'))
                            --l;

                     fprintf(fp, "Content-Type: text/plain");
                     fprintf(fp, "; format=flowed; delsp=yes"
                            "; charset=\"utf-8\"\n");
                     fprintf(fp, "Content-Transfer-Encoding: 8bit\n\n");

                     wrap_text_init(&uw, "utf-8", save_autoresponse, &fp);
                     wrap_text(&uw, autoresptxt, l);
              }

              if (fflush(fp) || ferror(fp))
              {
                     fclose(fp);
                     printf(getarg("SAVEFAILED"), strerror(errno));
                     return;
              }
              if (maildir_autoresponse_create_finish(NULL, autorespname, fp))
              {
                     if (errno == ENOSPC)
                     {
                            cgi_put("do.autorespedit", "1");
                            cgi_put("autoresponse_choose", autorespname);
                            cgi_put("replytext", cgi("text"));
                            printf(getarg("QUOTA"), strerror(errno));
                     }
                     else
                            printf(getarg("SAVEFAILED"), strerror(errno));
              }
              return;
       }

       if ( *cgi("do.autorespdelete"))
       {
              const char *autorespname=cgi("autoresponse_choose");

              if (mailfilter_autoreplyused(autorespname))
              {
                     char *s=folder_fromutf7(autorespname);
                     printf(getarg("INUSE"), s ? s:"");
                     if (s)
                            free(s);
              }
              else
                     maildir_autoresponse_delete(NULL, autorespname);
              return;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void autoresponselist ( )

Definition at line 552 of file autoresponse.c.

{
       char **list=maildir_autoresponse_list(NULL); /* I'm sorry... */
       size_t i;

       if (!list)
       {
              printf(getarg("ERROR"), strerror(errno));
              return;
       }

       for (i=0; list[i]; i++)
              ;

       qsort(list, i, sizeof(list[0]), &comp_autorespname);

       for (i=0; list[i]; i++)
       {
              char *s;

              printf("<option value=\"");
              output_attrencoded(list[i]);
              printf("\">");

              s=folder_fromutf7(list[i]);
              output_attrencoded(s);
              printf("</option>");
              free(s);
       }

       maildir_autoresponse_list_free(list);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void autoresponsepick ( )

Definition at line 585 of file autoresponse.c.

{
       char **list=maildir_autoresponse_list(NULL);
       size_t i;
       const char *choice=cgi("autoresponse_choose");

       if (!list)
       {
              printf(getarg("ERROR"), strerror(errno));
              return;
       }

       for (i=0; list[i]; i++)
              ;

       qsort(list, i, sizeof(list[0]), &comp_autorespname);

       for (i=0; list[i]; i++)
       {
              char *s;

              printf("<option%s value=\"",
                     strcmp(choice, list[i]) ? "":" selected='selected'");
              output_attrencoded(list[i]);
              printf("\">");

              s=folder_fromutf7(list[i]);
              output_attrencoded(s);
              printf("</option>");
              free(s);
       }

       maildir_autoresponse_list_free(list);
}

Here is the call graph for this function:

Here is the caller graph for this function: