@mail assistance

Posted by Onoitsu2 on Fri 28 Nov 2008 06:36 AM — 3 posts, 15,890 views.

USA #0
I have an alias for sending @mails easier, but would like to extend it some so it auto %r's it when a line reaches 65+ chars, but at the word boundary that crosses it, so the word that makes the line go over 65 chars would have a %r placed prior to it.

I am out of coding practice, and the whole use it or lose it applies to my brain and coding.


Alias Follows:
<aliases>
<alias
name="Compose_Mail"
match="^ComposeMail$"
enabled="y"
omit_from_command_history="y"
regexp="y"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>persons = utils.inputbox ( "Enter Person(s)'s Name", "Enter Addresse:")
if persons == nil then return end -- if
message = utils.editbox ( "Enter @Mail Message", "Enter Message:")
if message == nil then return end -- if
message_parse = Replace(message,"\\\\r\\\\n","/",false)
message_parse = Replace(message_parse,"\\\\r\\\\n","%%r",true)
message_parse = Replace(message_parse,"\\\\t","%%t",true)
SetCommand("@mail ".. persons.."="..message_parse)</send>
</alias>
</aliases>

-Onoitsu2
Australia Forum Administrator #1
Without writing the whole thing, I would imagine something like this might work:


for w in string.gmatch (message_parse, "%S+") do
  
  -- if (length of current line) + #w  > 65 then
  --  append %r
  -- end -- if

  -- append w to current line

end -- for


That is breaking your message up into batches of things that are not spaces (%S) and building them into lines.

However it is a bit fiddlier than that, because if there is already a %r in that batch, you have to reset the line length.

USA #2
I think I have created something that will sufficiently wrap my inputted message to about 65 characters, it will also wrap shorter if it runs into an sentence or question ending punctuation mark. Still buggy a little, but works well for what I needed it for.

-Onoitsu2


<aliases>
  <alias
   name="Compose_Mail"
   match="^ComposeMail$"
   enabled="y"
   omit_from_command_history="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>persons = utils.inputbox ( "Enter Person(s)'s Name", "Enter Addresse:")
if persons == nil then return end -- if
message = utils.editbox ( "Enter @Mail Message", "Enter Message:")
if message == nil then return end -- if

message = Replace(message,"\\r\\n","/",false)
message_start = string.find(message,"/",1,true)
title = string.sub(message,1,message_start-1)
message = string.sub(message,message_start+1)

message = Replace(message,"\\r\\n","%%r ",true)
message = Replace(message,"\\t","%%t ",true)

--print(title)
--print(message)

message_table = {}
line_length = 0
for word in string.gmatch (message, "%S+") do
line_length = line_length + #word + 1 -- add in possible space
--print(word .. " " .. #word)
--print(line_length)
  if string.match(word,"%%r ") then
    line_length = 0
    table.insert(message_table,word)
  else
    if string.match(word,"[%.%!%?]") and line_length &gt;= 65 then
      line_length = 0
      table.insert(message_table,word.."%r ")
    else
      if line_length &gt;= 75 then
        line_length = 0
        table.insert(message_table,word.."%r ")
      else
        table.insert(message_table,word)
      end -- if
    end -- if
  end -- if
end -- for
--print("----")
for k, v in ipairs (message_table) do
--print(v .. " " .. #v)
--print(#message)
  if k &gt; 1 then
    if string.match(v,"%%r ") then
      message = message .. v
    else
      if k == #message_table then
        message = message .. v
      else
        message = message .. v .. " "
      end -- if
    end -- if
  else
    message = v .. " "
  end -- if
end -- for

message = Replace(message,"%r ","%r",true)
message = Replace(message,"%t ","%t",true)
--print(message)

SetCommand("@mail ".. persons.."="..title.."/"..message)</send>
  </alias>
</aliases>

Amended on Tue 02 Dec 2008 11:37 AM by Onoitsu2