예제 #1
0
bool
wxEmail::Send(wxMailMessage& message,
              const wxString& profileName,
              const wxString& sendMail)
{
    wxASSERT_MSG( !message.m_to.IsEmpty(), _T("no recipients to send mail to") ) ;


    // The 'from' field is optionally supplied by the app; it's not needed
    // by MAPI, and on Unix, will be guessed if not supplied.
    wxString from = message.m_from;
    if ( from.empty() )
    {
        from = wxGetEmailAddress();
    }

    wxString msg;
    msg << wxT("To: ");

    const size_t rcptCount = message.m_to.GetCount();
    for (size_t rcpt = 0; rcpt < rcptCount; rcpt++)
    {
        if ( rcpt )
            msg << wxT(", ");
        msg << message.m_to[rcpt];
    }

    msg << wxT("\nFrom: ") << from << wxT("\nSubject: ") << message.m_subject;
    msg << wxT("\n\n") << message.m_body;

    wxString filename;
    filename.Printf(wxT("/tmp/msg-%ld-%ld-%ld.txt"), (long) getpid(), wxGetLocalTime(),
        (long) rand());

    {
        wxFileOutputStream stream(filename);
        if (stream.Ok())
        {
            stream.Write(msg, msg.Length());
        }
        else
        {
            return FALSE ;
        }
    }

    // TODO search for a suitable sendmail if sendMail is empty
    wxString sendmail(sendMail);

    wxString cmd;
    cmd << sendmail << wxT(" < ") << filename;

    // TODO: check return code
    wxSystem(cmd.c_str());

    wxRemoveFile(filename);

    return TRUE;
}
예제 #2
0
/* static */
wxImage &
wxIconManager::LoadImage(String filename, bool *success, bool showDlg)
{
   bool loaded = false;
   wxImage *img = new wxImage();

   // If we haven't been called yet, find out which image handlers
   // are supported:
   if(! m_knowHandlers) // first time initialisation
   {
      ms_NumOfHandlers = 0;
      for ( int i = 0; m_wxBitmapHandlers[i] != wxBITMAP_TYPE_MAX; i++ )
      {
         if ( !wxImage::FindHandler(m_wxBitmapHandlers[i]) )
            m_wxBitmapHandlers[i] = wxBITMAP_TYPE_INVALID; // not available
         else
            ms_NumOfHandlers ++;
      }

      m_knowHandlers = true;
   }

   // suppress any error logging from image handlers, some of them
   // will fail.
   {
      wxLogNull logNo;

      for ( int i = 0; m_wxBitmapHandlers[i] != wxBITMAP_TYPE_MAX; i++ )
      {
         if ( m_wxBitmapHandlers[i] != wxBITMAP_TYPE_INVALID )
         {
            if ( img->LoadFile(filename, m_wxBitmapHandlers[i]) )
               break;
         }
      }
   } // normal logging again

#ifdef OS_UNIX
   if(! loaded) // try to use imageMagick to convert image to another format:
   {
      String oldfilename = filename;
      String tempfile = filename;
      int format = READ_APPCONFIG(MP_TMPGFXFORMAT);
      if((format < 0 || format > NUMBER_OF_FORMATS)
         || (format != 0 &&
             m_wxBitmapHandlers[format] == wxBITMAP_TYPE_XPM)) //xpm we do ourselves
      {
         wxLogInfo(_("Unsupported intermediary image format '%s' specified,\n"
                     "reset to '%s'."),
                   ((format < 0 || format >NUMBER_OF_FORMATS) ?
                    _T("unknown") : HandlerNames[format]),
                   HandlerNames[0]);
         format = 0;
         mApplication->GetProfile()->writeEntry(MP_TMPGFXFORMAT,format);
      }
      tempfile += wxIconManagerFileExtensions[format];
      // strip leading path
      int i = tempfile.Length();
      while(i && tempfile.c_str()[i] != '/')
         i--;
      tempfile.assign(tempfile,i+1,tempfile.length()-1-i);
      tempfile = String(
         (wxGetenv(_T("TMP")) && wxStrlen(wxGetenv(_T("TMP"))))
         ? wxGetenv(_T("TMP")) : _T("/tmp")
         ) + _T('/') + tempfile;
      if(wxFile::Exists(filename))
      {
         String strConvertProgram = READ_APPCONFIG(MP_CONVERTPROGRAM);
         String strFormatSpec = strutil_extract_formatspec(strConvertProgram);
         if ( strFormatSpec != _T("ss") )
         {
            wxLogError(_("The setting for image conversion program should include "
                         "exactly two '%%s' format specificators.\n"
                         "The current setting '%s' is incorrect and "
                         "the default value will be used instead."),
                       strConvertProgram.c_str());
            strConvertProgram = GetStringDefault(MP_CONVERTPROGRAM);
         }
         String command;
         command.Printf(strConvertProgram, filename.c_str(), tempfile.c_str());
         wxLogTrace(wxTraceIconLoading,
                    _T("wxIconManager::LoadImage() calling '%s'..."),
                    command.c_str());
         if(wxSystem(command) == 0)
         {
            wxLogNull lo; // suppress error messages
            if(format != 0) // not xpm which we handle internally
            {
               switch(format)
               {
               case 1: // PNG!
                  loaded = img->LoadFile(tempfile, wxBITMAP_TYPE_PNG);
                  break;
               case 2: // 2 BMP
                  loaded = img->LoadFile(tempfile, wxBITMAP_TYPE_BMP);
                  break;
               case 3: // 3 JPG
                  loaded = img->LoadFile(tempfile, wxBITMAP_TYPE_JPEG);
                  break;
               }
            }
         } // system()
         if(tempfile.length()) // using a temporary file
            wxRemoveFile(tempfile);
      }// if(wxFile::Exists())
   }//! loaded
#endif // OS_UNIX

   // if everything else failed, try xpm loading:
   if( !loaded ) // try our own XPM loading code
   {
      char ** cpptr = LoadImageXpm(filename);
      if(cpptr)
      {
         *img = wxBitmap(cpptr).ConvertToImage();
         wxIconManager::FreeImage(cpptr);
         loaded = true;
      }
   }
   if(success)
      *success = loaded;
   return *img;
}
예제 #3
0
파일: email.cpp 프로젝트: AluOne/OpenCPN
bool wxEmail::Send(wxMailMessage& message,  int sendMethod, const wxString& profileName,
    const wxString& sendMail2, const wxString& sendMail1, const wxString& sendMail0)
{
    wxASSERT_MSG( !message.m_to.IsEmpty(), _T("no recipients to send mail to") ) ;

    wxString from = message.m_from;
    if ( from.empty() )
    {
        from = wxGetEmailAddress();
    }

    wxString msg,sendmail;

    if(sendMethod == 0) {                    //with xdg-email via local mail system (MUA)

    if(wxFileExists(sendMail0))
        sendmail << sendMail0;
    else if(wxFileExists(sendMail1))
        sendmail << sendMail1;
    else {
    wxLogMessage(_T("MAIL Error: xdg-email is not installed on this computer!") );
    return false;
    }

    msg << wxT("sh") << wxT(" ") << sendmail << wxT(" --utf8");                     //command
    msg << wxT(" --subject") <<  wxT(" '") << message.m_subject  << wxT("' ");      //subject argument
    msg << wxT("--body") << wxT(" '") << message.m_body << wxT("'");                //body argument

    for (size_t rcpt = 0; rcpt < message.m_to.GetCount(); rcpt++)                   //mail to argument
        msg << wxT(" '") << message.m_to[rcpt] << wxT("'");

    wxSystem(msg.c_str());

    return true;

    } else {                                 //directly with sendmail
        msg << wxT("To: ");
        for (size_t rcpt = 0; rcpt < message.m_to.GetCount(); rcpt++) {
            if ( rcpt ) msg << wxT(", ");
            msg << message.m_to[rcpt];
        }
        msg << wxT("\nFrom: ") << from << wxT("\nSubject: ") << message.m_subject;
        msg << wxT("\n\n") << message.m_body;

        wxString filename;
        filename.Printf(wxT("/tmp/msg-%ld-%ld-%ld.txt"), (long) getpid(), wxGetLocalTime(),
            (long) rand());

        wxFileOutputStream stream(filename);
        if (stream.Ok())
            stream.Write(msg.ToUTF8(), msg.Length());
        else
            return FALSE;

        // TODO search for a suitable sendmail if sendMail is empty
        sendmail << sendMail2;

        wxString cmd;
        cmd << sendmail << wxT(" < ") << filename;

        // TODO: check return code
        wxSystem(cmd.c_str());

        wxRemoveFile(filename);

        return TRUE;
    }
}