Example #1
0
        // connect
        //        return false on sucess or true on cancel
        public bool connect()
        {
            host = Settings.Hostname;
            port = Convert.ToInt32(Settings.Port);
            user = Settings.Username;
            if (gfax.hylafaxPassword == null)	// if we already entered a pass but
                if (Settings.Password != "")	// don't want to remember it it won't be null
                    gfax.hylafaxPassword = Settings.Password;

            if (Settings.Faxtracing == true) {
                Console.WriteLine ("Initializing hylafax class .......");
            }

            try {
                mainclient.Connect(host, port);
              		mainstream = mainclient.GetStream();
                string s = read(mainstream, mainclient);
                if (Settings.Faxtracing == true) {
                    Console.WriteLine ("[hylafax.connect] on connect : {0}", s);
                }

                if(mainstream.CanWrite && mainstream.CanRead){
              	    	// Write username
                    if (Settings.Faxtracing == true) {
                        Console.WriteLine ("[hylafax.connect] Sending USER : {0}", user);
                    }

                    //If the username is null then hylafax doesn't need usernames
                    // TODO check the hylafax protocol about this
                    if (user == "")
                        user = "******";

                    write (mainstream, "USER " + user + "\n");
                    // Read result
                    // If the result is ("230 User <username> logged in.")
                    // 		I don't need to send a password
                    // Else if the result is ("331 Password required for <username>.")
                    //		I must send a password.
              	    	string returndata = read(mainstream, mainclient);

                    if (returndata.Substring(0,3) == "331") {
                        //Console.WriteLine("Password is {0}", gfax.hylafaxPassword);
                        for (int i = 0; i < 3; i++) {

                            if (gfax.hylafaxPassword == null) {
                                G_Password gpass = new G_Password();
                                gpass.Run();

                                if (gpass.Cancel) {
                                    return false;  // connection cancelled
                                }
                                gfax.hylafaxPassword = gpass.Password;
                                if (gpass.RememberPassword)
                                    Settings.Password = gpass.Password;
                                gpass.Close();
                            }
                            // 530 Login incorrect. result from bad password
                            //prompt for password
                            write (mainstream, "PASS " + gfax.hylafaxPassword + "\n");

                            string rtn = read(mainstream, mainclient);
                            //Console.WriteLine("Return is {0}", rtn);
                            if (rtn.Substring(0,3) == "230")  // user is logged in
                                break;
                            else {
                                gfax.hylafaxPassword = null;
                                write (mainstream, "USER " + user + "\n");
              	    				string rtndata = read(mainstream, mainclient);
                            }
                        }
                    }

                    if (Settings.Faxtracing == true) {
                        Console.WriteLine("[hylafax.connect] USER returned : {0}", returndata);
                    }
                }
                else if (!mainstream.CanRead) {
                    Console.WriteLine(Catalog.GetString("You can not write data to this stream"));
                    mainclient.Close();
                }
                else if (!mainstream.CanWrite) {
                    Console.WriteLine(Catalog.GetString("You can not read data from this stream"));
                    mainclient.Close();
                }

                return true;
            }
            catch (Exception e ) {
                Console.WriteLine(e.ToString());
                G_Message m = new G_Message(Catalog.GetString("Could not connect to your Hylafax server.\n" +
                    "Check console messages for further information\n\n" +
                    "You might need to set a value for username."));
                return false;
            }
        }
Example #2
0
        // connect
        //		return false on sucess or true on cancel
        public bool connect()
        {
            host = Settings.Hostname;
            port = Convert.ToInt32(Settings.Port);
            user = Settings.Username;
            if (gfax.hylafaxPassword == null)                   // if we already entered a pass but
            {
                if (Settings.Password != "")                    // don't want to remember it it won't be null
                {
                    gfax.hylafaxPassword = Settings.Password;
                }
            }

            if (Settings.Faxtracing == true)
            {
                Console.WriteLine("Initializing hylafax class .......");
            }

            try {
                mainclient.Connect(host, port);
                mainstream = mainclient.GetStream();
                string s = read(mainstream, mainclient);
                if (Settings.Faxtracing == true)
                {
                    Console.WriteLine("[hylafax.connect] on connect : {0}", s);
                }


                if (mainstream.CanWrite && mainstream.CanRead)
                {
                    // Write username
                    if (Settings.Faxtracing == true)
                    {
                        Console.WriteLine("[hylafax.connect] Sending USER : {0}", user);
                    }

                    //If the username is null then hylafax doesn't need usernames
                    // TODO check the hylafax protocol about this
                    if (user == "")
                    {
                        user = "******";
                    }

                    write(mainstream, "USER " + user + "\n");
                    // Read result
                    // If the result is ("230 User <username> logged in.")
                    //      I don't need to send a password
                    // Else if the result is ("331 Password required for <username>.")
                    //		I must send a password.
                    string returndata = read(mainstream, mainclient);

                    if (returndata.Substring(0, 3) == "331")
                    {
                        //Console.WriteLine("Password is {0}", gfax.hylafaxPassword);
                        for (int i = 0; i < 3; i++)
                        {
                            if (gfax.hylafaxPassword == null)
                            {
                                G_Password gpass = new G_Password();
                                gpass.Run();

                                if (gpass.Cancel)
                                {
                                    return(false);                                     // connection cancelled
                                }
                                gfax.hylafaxPassword = gpass.Password;
                                if (gpass.RememberPassword)
                                {
                                    Settings.Password = gpass.Password;
                                }
                                gpass.Close();
                            }
                            // 530 Login incorrect. result from bad password
                            //prompt for password
                            write(mainstream, "PASS " + gfax.hylafaxPassword + "\n");

                            string rtn = read(mainstream, mainclient);
                            //Console.WriteLine("Return is {0}", rtn);
                            if (rtn.Substring(0, 3) == "230")                             // user is logged in
                            {
                                break;
                            }
                            else
                            {
                                gfax.hylafaxPassword = null;
                                write(mainstream, "USER " + user + "\n");
                                string rtndata = read(mainstream, mainclient);
                            }
                        }
                    }

                    if (Settings.Faxtracing == true)
                    {
                        Console.WriteLine("[hylafax.connect] USER returned : {0}", returndata);
                    }
                }
                else if (!mainstream.CanRead)
                {
                    Console.WriteLine(Catalog.GetString("You can not write data to this stream"));
                    mainclient.Close();
                }
                else if (!mainstream.CanWrite)
                {
                    Console.WriteLine(Catalog.GetString("You can not read data from this stream"));
                    mainclient.Close();
                }

                return(true);
            }
            catch (Exception e) {
                Console.WriteLine(e.ToString());
                G_Message m = new G_Message(Catalog.GetString("Could not connect to your Hylafax server.\n" +
                                                              "Check console messages for further information\n\n" +
                                                              "You might need to set a value for username."));
                return(false);
            }
        }