/**************************************************************************** * name: fileOrServer * purpose: Given a string, checks to see if it can stat it. If so, it is * assumed the user expects to open the file, not a web site. If not, we * assume it is supposed to be a server and prepend the default protocol. * inputs: * - char *url: URL to canonicalize. * returns: * The canonical representation of the URL. * remarks: * Written by [email protected] ****************************************************************************/ char *fileOrServer(char *url) { struct stat buf; char *xurl; /* * At this point we know the URL specified is of the form: * shire.ncsa.uiuc.edu[:PORT]/path/to/something */ if (!stat(url,&buf)) { /*its a file and we have access*/ xurl=mo_url_canonicalize_local(url); } else if (!(get_pref_string(eDEFAULT_PROTOCOL)) || !*(get_pref_string(eDEFAULT_PROTOCOL))) { xurl=(char *)calloc(strlen(url)+15,sizeof(char)); sprintf(xurl,"http://%s",url); } else { xurl=(char *)calloc(strlen(url)+strlen(get_pref_string(eDEFAULT_PROTOCOL))+10,sizeof(char)); sprintf(xurl,"%s://%s",get_pref_string(eDEFAULT_PROTOCOL),url); } return(xurl); }
/**************************************************************************** * name: mo_url_prepend_protocol * purpose: To prepend the proper protocol to the url if it is not present. * inputs: * - char *url: URL to canonicalize. * returns: * The canonical representation of the URL. * remarks: * Contributed by [email protected], modified by [email protected] ****************************************************************************/ char *mo_url_prepend_protocol(char *url) { char *xurl; if (!url || !*url) { return(NULL); } if (!get_pref_string(eEXPAND_URLS)) { if (!strchr(url,':')) { /*no colon found, treat as file*/ xurl = mo_url_canonicalize_local (url); } else { /*its prolly a real url*/ xurl=strdup(url); } } else if (strncasecmp(url,"mailto:",7) && strncasecmp(url,"news:",5) && strncasecmp(url,"about:",6) && !strstr(url,"://")) { /*no protocol specified, default*/ if (get_pref_string(eEXPAND_URLS_WITH_NAME)) { if (!strncmp(url, "www.", 4)) { xurl = (char *)malloc(strlen(url) + (8 * sizeof(char))); sprintf(xurl, "http://%s", url); } else if (!strncmp(url, "ftp.", 4)) { xurl = (char *)malloc(strlen(url) + (7 * sizeof(char))); sprintf(xurl, "ftp://%s", url); } else if (!strncmp(url, "gopher.", 7)) { xurl = (char *)malloc(strlen(url) + (10 * sizeof(char))); sprintf(xurl, "gopher://%s", url); } else if (!strncmp(url, "wais.", 5)) { xurl = (char *)malloc(strlen(url) + (8 * sizeof(char))); sprintf(xurl, "wais://%s", url); } else { xurl=fileOrServer(url); } } else { xurl=fileOrServer(url); } } else { /*protocol was specified*/ xurl=strdup(url); } return(xurl); }
char *mo_tmpnam (char *url) { extern void MoCCIAddFileURLToList(char *, char *); char *tmp = (char *)malloc (sizeof (char) * L_tmpnam); char *tmp_dir = get_pref_string(eTMP_DIRECTORY); tmpnam (tmp); if (!tmp_dir) { /* Fast path. */ if(url) MoCCIAddFileURLToList(tmp,url); return tmp; } else { /* OK, reconstruct to go in the directory of our choice. */ char *oldtmp = tmp; int i; /* Start at the back and work our way forward. */ for (i = strlen(oldtmp)-1; i >= 0; i--) { if (oldtmp[i] == '/') goto found_it; } /* No luck, just punt. */ if(url) MoCCIAddFileURLToList(tmp,url); return tmp; found_it: tmp = (char *)malloc (sizeof (char) * (strlen (tmp_dir) + strlen (&(oldtmp[i])) + 8)); if (tmp_dir[strlen(tmp_dir)-1] == '/') { /* Trailing slash in tmp_directory spec. */ sprintf (tmp, "%s%s", tmp_dir, &(oldtmp[i])+1); } else { /* No trailing slash. */ sprintf (tmp, "%s%s", tmp_dir, &(oldtmp[i])); } MoCCIAddFileURLToList(tmp,url); free (oldtmp); return tmp; } }
FILE *mo_start_sending_mail_message (char *to, char *subj, char *content_type, char *url) { char cmd[2048]; char *tmp; if (!to) return NULL; if(!strcmp(content_type,"url_only")){ content_type = "text/plain"; } #ifdef OLD if (get_pref_string(eMAIL_FILTER_COMMAND)) { sprintf (cmd, "%s | %s -t", get_pref_string(eMAIL_FILTER_COMMAND), get_pref_string(eSENDMAIL_COMMAND)); } else { sprintf (cmd, "%s -t", get_pref_string(eSENDMAIL_COMMAND)); } #else /* Try listing address on command line. */ for (tmp = to; *tmp; tmp++) if (*tmp == ',') *tmp = ' '; if (get_pref_string(eMAIL_FILTER_COMMAND) && content_type && strcmp (content_type, "application/postscript")) { sprintf (cmd, "%s | %s %s", get_pref_string(eMAIL_FILTER_COMMAND), get_pref_string(eSENDMAIL_COMMAND), to); } else { sprintf (cmd, "%s %s", get_pref_string(eSENDMAIL_COMMAND), to); } #endif if ((_fp = popen (cmd, "w")) == NULL) return NULL; fprintf (_fp, "To: %s\n", to); fprintf (_fp, "Subject: %s\n", subj); fprintf (_fp, "Reply-To: %s <%s>\n",get_pref_string(eDEFAULT_AUTHOR_NAME),get_pref_string(eDEFAULT_AUTHOR_EMAIL)); fprintf (_fp, "Content-Type: %s\n", content_type); fprintf (_fp, "Mime-Version: 1.0\n"); fprintf (_fp, "X-Mailer: NCSA Mosaic %s on %s\n", MO_VERSION_STRING, MO_MACHINE_TYPE); if (url) fprintf (_fp, "X-URL: %s\n", url); fprintf (_fp, "\n"); /* Stick in BASE tag as appropriate. */ if (url && content_type && strcmp (content_type, "text/x-html") == 0) fprintf (_fp, "<base href=\"%s\">\n", url); return _fp; }
static XmxCallback (mailhist_win_cb) { mo_window *win = mo_fetch_window_by_id (XmxExtractUniqid ((int)client_data)); char *to, *subj; FILE *fp; switch (XmxExtractToken ((int)client_data)) { case 0: XtUnmanageChild (win->mailhist_win); mo_busy (); to = XmxTextGetString (win->mailhist_to_text); if (!to) return; if (to[0] == '\0') return; subj = XmxTextGetString (win->mailhist_subj_text); /* Open a file descriptor to sendmail. */ fp = mo_start_sending_mail_message (to, subj, "text/x-html", NULL); if (!fp) goto oops; { mo_node *node; fprintf (fp, "<HTML>\n"); fprintf (fp, "<H1>History Path From %s</H1>\n", get_pref_string(eDEFAULT_AUTHOR_NAME)); fprintf (fp, "<DL>\n"); for (node = win->history; node != NULL; node = node->next) { fprintf (fp, "<DT>%s\n<DD><A HREF=\"%s\">%s</A>\n", node->title, node->url, node->url); } fprintf (fp, "</DL>\n"); fprintf (fp, "</HTML>\n"); } mo_finish_sending_mail_message (); oops: free (to); free (subj); mo_not_busy (); break; case 1: XtUnmanageChild (win->mailhist_win); /* Do nothing. */ break; case 2: mo_open_another_window (win, mo_assemble_help_url ("help-on-nested-hotlists.html"), NULL, NULL); break; } return; }