A follow-on patch to use the hostname in the path so an item named
"jsmith" for website www.example.com or example.com is saved as:

$HOME/.password-store/example.com/jsmith.gpg

Also imports all items in the Passwords column under the Passwords
directory.

jf

On Sat, 2019-08-31 at 11:46 -0400, John Franklin wrote:
> The following patch does the following:
> 
>   Some changes to improve the naming of entries from 1Password:
>   - Use the location as an alternate name, if there is no title
>   - Use 'Untitled' if no reasonable name can be found.
>   - Santize the filename, removing some characters that just cause
> trouble.
>   - Increment a suffix on the filename until we find one that's not
> in
> use.
>   - Rename pass[:name] to pass[:entryName] as there may be a name
> field.
> 
> jf
> _______________________________________________
> Password-Store mailing list
> [email protected]
> https://lists.zx2c4.com/mailman/listinfo/password-store
-- 
John Franklin
[email protected]
diff --git a/contrib/importers/1password2pass.rb b/contrib/importers/1password2pass.rb
index 87cc6ba..6419a30 100755
--- a/contrib/importers/1password2pass.rb
+++ b/contrib/importers/1password2pass.rb
@@ -108,8 +108,7 @@ elsif File.extname(filename) =~ /.1pif/i
 
   # Import 1PIF
   JSON.parse("[#{pif}]", symbolize_names: true).each do |entry|
-    next unless entry[:typeName] == "webforms.WebForm"
-    next if entry[:secureContents][:fields].nil?
+    next unless ["webforms.WebForm", "passwords.Password"].include? entry[:typeName]
 
     pass = {}
 
@@ -117,6 +116,7 @@ elsif File.extname(filename) =~ /.1pif/i
     entryName = "Untitled" if entryName.to_s.empty?
     entryName = entryName.gsub(/[:\*\[\]\|]/, "-")
     pass[:entryName] = "#{(options.group + "/") if options.group}#{entryName}"
+    pass[:entryType] = entry[:typeName]
 
     pass[:title] = entry[:title]
 
@@ -131,6 +131,7 @@ elsif File.extname(filename) =~ /.1pif/i
     pass[:login] = username[:value] if username
 
     pass[:url] = entry[:location]
+    pass[:urlKey] = entry[:locationKey] if (entry[:locationKey] && !entry[:locationKey].empty?)
     pass[:notes] = entry[:secureContents][:notesPlain]
     passwords << pass
   end
@@ -141,13 +142,14 @@ puts "Read #{passwords.length} passwords."
 errors = []
 # Save the passwords
 passwords.each do |pass|
+  host = pass[:urlKey] || "Passwords" if pass[:entryType] == "passwords.Password" || "."
   base_fname = pass[:entryName].split('/').collect(&:strip).join('/') || "Untitled"
   suffix=0
-  fname = "#{base_fname}"
+  fname = "#{host}/#{base_fname}"
   exit if fname.empty?
   while !options.force && (File.exists?("#{passroot}/#{fname}.gpg"))
     suffix += 1
-    fname = "#{base_fname}-#{suffix.to_s}"
+    fname = "#{host}/#{base_fname}-#{suffix.to_s}"
   end
   IO.popen("pass insert #{"-f " if options.force}-m \"#{fname}\" > /dev/null", "w") do |io|
     io.puts pass[:password]
_______________________________________________
Password-Store mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to